From 10a4c30bf59bbf4836938a53c8755dc0109b964f Mon Sep 17 00:00:00 2001 From: Awstin Date: Wed, 10 Jul 2024 06:55:38 -0400 Subject: [PATCH] Removed unneeded js delivery for site, removed active_navbar from backend --- src/html/blog.rs | 5 +---- src/html/mod.rs | 14 -------------- src/html/projects.rs | 15 +++++++-------- src/html/root.rs | 36 +++++++++--------------------------- templates/base.html | 4 +--- 5 files changed, 18 insertions(+), 56 deletions(-) diff --git a/src/html/blog.rs b/src/html/blog.rs index 50b7b98..e341363 100644 --- a/src/html/blog.rs +++ b/src/html/blog.rs @@ -9,7 +9,7 @@ use core::panic; use sqlx::PgPool; use std::{collections::HashMap, error::Error}; -use super::{root::AppState, ArticleTemplate, HtmlTemplate, NavBar}; +use super::{root::AppState, ArticleTemplate, HtmlTemplate}; pub fn get_router() -> Router { Router::new() @@ -23,7 +23,6 @@ async fn blog(state: Extension) -> impl IntoResponse { .await .expect("couldn't get articles"); let template = BlogTemplate { - active_navbar: NavBar::BLOG, article_list: list.join("\n"), }; HtmlTemplate(template) @@ -32,7 +31,6 @@ async fn blog(state: Extension) -> impl IntoResponse { #[derive(Template)] #[template(path = "blog.html")] struct BlogTemplate { - active_navbar: &'static str, article_list: String, } @@ -64,7 +62,6 @@ async fn article( }, }; let template = ArticleTemplate { - active_navbar: NavBar::BLOG, content: article.content, footer: footer.to_string(), }; diff --git a/src/html/mod.rs b/src/html/mod.rs index a0872d1..d65164a 100644 --- a/src/html/mod.rs +++ b/src/html/mod.rs @@ -31,23 +31,9 @@ where } } -#[non_exhaustive] -pub struct NavBar { -} - -impl NavBar { - pub const HOME: &'static str = ""; - pub const BLOG: &'static str = "blog"; - pub const PROJECTS: &'static str = "projects"; - pub const NOW: &'static str = "now"; - pub const ABOUT: &'static str = "about"; - pub const CONTACT: &'static str = "contact"; -} - #[derive(Template)] #[template(path = "article.html")] pub struct ArticleTemplate { - active_navbar: &'static str, footer: String, content: String, } diff --git a/src/html/projects.rs b/src/html/projects.rs index 7a9cc4c..77d8748 100644 --- a/src/html/projects.rs +++ b/src/html/projects.rs @@ -1,12 +1,12 @@ -use achubb_database::data::{PsqlData, project::Project}; -use axum::extract::{Extension, Path}; +use achubb_database::data::{project::Project, PsqlData}; use askama::Template; +use axum::extract::{Extension, Path}; use axum::response::IntoResponse; use axum::{routing::get, Router}; -use std::{ error::Error, collections::HashMap}; use sqlx::PgPool; +use std::{collections::HashMap, error::Error}; -use super::{root::AppState, ArticleTemplate, HtmlTemplate, NavBar}; +use super::{root::AppState, ArticleTemplate, HtmlTemplate}; pub fn get_router() -> Router { Router::new() @@ -20,7 +20,6 @@ pub async fn projects(state: Extension) -> impl IntoResponse { .await .expect("couldn't get projects"); let template = ProjectsTemplate { - active_navbar: NavBar::PROJECTS, project_list: list.join("\n"), }; HtmlTemplate(template) @@ -29,7 +28,6 @@ pub async fn projects(state: Extension) -> impl IntoResponse { #[derive(Template)] #[template(path = "projects.html")] struct ProjectsTemplate { - active_navbar: &'static str, project_list: String, } @@ -45,8 +43,9 @@ async fn project( }; let footer: &str = "Back to Projects"; let template = ArticleTemplate { - active_navbar: NavBar::PROJECTS, - content: project.content.expect("Should have had content if it got this far"), + content: project + .content + .expect("Should have had content if it got this far"), footer: footer.to_string(), }; HtmlTemplate(template) diff --git a/src/html/root.rs b/src/html/root.rs index c701e9c..662faaf 100644 --- a/src/html/root.rs +++ b/src/html/root.rs @@ -1,4 +1,4 @@ -use crate::html::{api, blog, projects, HtmlTemplate, NavBar}; +use crate::html::{api, blog, projects, HtmlTemplate}; use askama::Template; use axum::{ response::{IntoResponse, Redirect}, @@ -53,7 +53,6 @@ async fn home(state: Extension) -> impl IntoResponse { let (project_head, _) = project_list.split_at(5); let template = HomeTemplate { - active_navbar: NavBar::HOME, recent_blogs: article_head.join("\n"), recent_projects: project_head.join("\n"), }; @@ -63,59 +62,42 @@ async fn home(state: Extension) -> impl IntoResponse { #[derive(Template)] #[template(path = "home.html")] struct HomeTemplate { - active_navbar: &'static str, recent_blogs: String, recent_projects: String, } async fn now() -> impl IntoResponse { - let template = NowTemplate { - active_navbar: NavBar::NOW, - }; + let template = NowTemplate {}; HtmlTemplate(template) } #[derive(Template)] #[template(path = "now.html")] -struct NowTemplate { - active_navbar: &'static str, -} +struct NowTemplate {} async fn about() -> impl IntoResponse { - let template = AboutTemplate { - active_navbar: NavBar::ABOUT, - }; + let template = AboutTemplate {}; HtmlTemplate(template) } #[derive(Template)] #[template(path = "about.html")] -struct AboutTemplate { - active_navbar: &'static str, -} +struct AboutTemplate {} async fn contact() -> impl IntoResponse { - let template = ContactTemplate { - active_navbar: NavBar::CONTACT, - }; + let template = ContactTemplate {}; HtmlTemplate(template) } #[derive(Template)] #[template(path = "contact.html")] -struct ContactTemplate { - active_navbar: &'static str, -} +struct ContactTemplate {} async fn uses() -> impl IntoResponse { - let template = UsesTemplate{ - active_navbar: NavBar::ABOUT, - }; + let template = UsesTemplate {}; HtmlTemplate(template) } #[derive(Template)] #[template(path = "uses.html")] -struct UsesTemplate { - active_navbar: &'static str, -} +struct UsesTemplate {} diff --git a/templates/base.html b/templates/base.html index aa4655f..8c5eec9 100644 --- a/templates/base.html +++ b/templates/base.html @@ -3,14 +3,12 @@ - - Awstin {% block head %}{% endblock %} - +