diff --git a/axum_server/src/components/mod.rs b/axum_server/src/components/mod.rs index 3b29951..9164ff5 100644 --- a/axum_server/src/components/mod.rs +++ b/axum_server/src/components/mod.rs @@ -1,2 +1 @@ -pub mod site_footer; pub mod site_header; diff --git a/axum_server/src/components/site_footer.rs b/axum_server/src/components/site_footer.rs deleted file mode 100644 index d4dcb92..0000000 --- a/axum_server/src/components/site_footer.rs +++ /dev/null @@ -1,26 +0,0 @@ -use askama::Template; -use axum::http::StatusCode; - -use crate::{ - blog_posts::blog_post_model::{BlogPostMetadata, BLOG_POST_PATH}, - post_utils::{post_listing::get_post_list, post_parser::ParseResult}, -}; - -#[derive(Template)] -#[template(path = "site_footer.html")] -pub struct SiteFooter { - pub latest_posts: Vec>, -} - -// TODO remove whole site footer anyway -pub async fn render_site_footer() -> Result { - let mut post_list = get_post_list::(BLOG_POST_PATH).await?; - post_list.sort_by_key(|post| post.metadata.date); - post_list.reverse(); - - let latest_posts = post_list - .into_iter() - .take(6) - .collect::>>(); - Ok(SiteFooter { latest_posts }) -} diff --git a/axum_server/src/pages/blog_post_list.rs b/axum_server/src/pages/blog_post_list.rs index b4b2e0f..4869147 100644 --- a/axum_server/src/pages/blog_post_list.rs +++ b/axum_server/src/pages/blog_post_list.rs @@ -3,10 +3,7 @@ use axum::{extract::Path, http::StatusCode}; use crate::{ blog_posts::blog_post_model::{BlogPostMetadata, BLOG_POST_PATH}, - components::{ - site_footer::{render_site_footer, SiteFooter}, - site_header::{HeaderProps, Link}, - }, + components::site_header::{HeaderProps, Link}, filters, post_utils::{post_listing::get_post_list, post_parser::ParseResult}, }; @@ -17,7 +14,6 @@ pub struct PostListTemplate { pub title: String, pub posts: Vec>, pub tag: Option, - pub site_footer: SiteFooter, pub header_props: HeaderProps, } @@ -27,7 +23,6 @@ pub async fn render_blog_post_list( // I will forget what happens here in a week. But essentially it's pattern matching and shadowing let tag = tag.map(|Path(tag)| tag); - let site_footer = render_site_footer().await?; let mut post_list = get_post_list::(BLOG_POST_PATH).await?; post_list.sort_by_key(|post| post.metadata.date); post_list.retain(|post| post.metadata.published); @@ -60,7 +55,6 @@ pub async fn render_blog_post_list( title: "Posts".to_owned(), posts, tag, - site_footer, header_props, }) } diff --git a/axum_server/src/pages/blog_post_page.rs b/axum_server/src/pages/blog_post_page.rs index e0537ca..3993379 100644 --- a/axum_server/src/pages/blog_post_page.rs +++ b/axum_server/src/pages/blog_post_page.rs @@ -1,17 +1,13 @@ use askama::Template; use axum::{extract::Path, http::StatusCode}; use chrono::{DateTime, Utc}; -use tokio::try_join; use crate::{ blog_posts::blog_post_model::BlogPostMetadata, components::site_header::Link, filters, post_utils::post_parser::parse_post, }; -use crate::components::{ - site_footer::{render_site_footer, SiteFooter}, - site_header::HeaderProps, -}; +use crate::components::site_header::HeaderProps; #[derive(Template)] #[template(path = "blog_post.html")] @@ -20,21 +16,19 @@ pub struct BlogPostTemplate { pub body: String, pub date: DateTime, pub tags: Vec, - pub site_footer: SiteFooter, pub header_props: HeaderProps, } pub async fn render_blog_post(Path(post_id): Path) -> Result { let path = format!("../_posts/blog/{}.md", post_id); let parse_post = parse_post::(&path); - let (site_footer, parsed) = try_join!(render_site_footer(), parse_post)?; + let parsed = parse_post.await?; Ok(BlogPostTemplate { title: parsed.metadata.title, date: parsed.metadata.date, tags: parsed.metadata.tags, body: parsed.body, - site_footer, header_props: HeaderProps::with_back_link(Link { href: "/blog".to_string(), label: "All posts".to_string(), diff --git a/axum_server/src/pages/contact.rs b/axum_server/src/pages/contact.rs index cb0f160..4837dea 100644 --- a/axum_server/src/pages/contact.rs +++ b/axum_server/src/pages/contact.rs @@ -1,10 +1,7 @@ use askama::Template; use axum::http::StatusCode; -use crate::components::{ - site_footer::{render_site_footer, SiteFooter}, - site_header::HeaderProps, -}; +use crate::components::site_header::HeaderProps; pub struct ContactLink { pub href: String, @@ -17,13 +14,11 @@ pub struct ContactLink { #[template(path = "contact.html")] pub struct ContactPageTemplate { pub title: String, - pub site_footer: SiteFooter, pub header_props: HeaderProps, pub links: Vec, } pub async fn render_contact() -> Result { - let site_footer = render_site_footer().await?; let links = vec![ ContactLink { href: "mailto: michalvankosk@gmail.com".to_string(), @@ -77,7 +72,6 @@ pub async fn render_contact() -> Result { Ok(ContactPageTemplate { title: "Contact".to_owned(), - site_footer, header_props: HeaderProps::default(), links, }) diff --git a/axum_server/src/pages/index.rs b/axum_server/src/pages/index.rs index 826d71e..48d3690 100644 --- a/axum_server/src/pages/index.rs +++ b/axum_server/src/pages/index.rs @@ -7,10 +7,7 @@ use crate::{ blog_post_model::BlogPostMetadata, featured_blog_posts::get_featured_blog_posts, tag_list::get_popular_blog_tags, }, - components::{ - site_footer::{render_site_footer, SiteFooter}, - site_header::HeaderProps, - }, + components::site_header::HeaderProps, filters, post_utils::post_parser::ParseResult, projects::{featured_projects::get_featured_projects, project_model::ProjectMetadata}, @@ -19,7 +16,6 @@ use crate::{ #[derive(Template)] #[template(path = "index.html")] pub struct IndexTemplate { - site_footer: SiteFooter, header_props: HeaderProps, blog_tags: Vec, featured_blog_posts: Vec>, @@ -27,15 +23,13 @@ pub struct IndexTemplate { } pub async fn render_index() -> Result { - let (site_footer, blog_tags, featured_blog_posts, featured_projects) = try_join!( - render_site_footer(), + let (blog_tags, featured_blog_posts, featured_projects) = try_join!( get_popular_blog_tags(), get_featured_blog_posts(), get_featured_projects() )?; Ok(IndexTemplate { - site_footer, header_props: HeaderProps::default(), blog_tags, featured_blog_posts,