remove site_footer rust code

This commit is contained in:
Michal Vanko 2024-09-06 11:28:40 +02:00
parent 64efecfde2
commit b136f46a6f
6 changed files with 6 additions and 57 deletions

View File

@ -1,2 +1 @@
pub mod site_footer;
pub mod site_header; pub mod site_header;

View File

@ -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<ParseResult<BlogPostMetadata>>,
}
// TODO remove whole site footer anyway
pub async fn render_site_footer() -> Result<SiteFooter, StatusCode> {
let mut post_list = get_post_list::<BlogPostMetadata>(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::<Vec<ParseResult<BlogPostMetadata>>>();
Ok(SiteFooter { latest_posts })
}

View File

@ -3,10 +3,7 @@ use axum::{extract::Path, http::StatusCode};
use crate::{ use crate::{
blog_posts::blog_post_model::{BlogPostMetadata, BLOG_POST_PATH}, blog_posts::blog_post_model::{BlogPostMetadata, BLOG_POST_PATH},
components::{ components::site_header::{HeaderProps, Link},
site_footer::{render_site_footer, SiteFooter},
site_header::{HeaderProps, Link},
},
filters, filters,
post_utils::{post_listing::get_post_list, post_parser::ParseResult}, post_utils::{post_listing::get_post_list, post_parser::ParseResult},
}; };
@ -17,7 +14,6 @@ pub struct PostListTemplate {
pub title: String, pub title: String,
pub posts: Vec<ParseResult<BlogPostMetadata>>, pub posts: Vec<ParseResult<BlogPostMetadata>>,
pub tag: Option<String>, pub tag: Option<String>,
pub site_footer: SiteFooter,
pub header_props: HeaderProps, 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 // 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 tag = tag.map(|Path(tag)| tag);
let site_footer = render_site_footer().await?;
let mut post_list = get_post_list::<BlogPostMetadata>(BLOG_POST_PATH).await?; let mut post_list = get_post_list::<BlogPostMetadata>(BLOG_POST_PATH).await?;
post_list.sort_by_key(|post| post.metadata.date); post_list.sort_by_key(|post| post.metadata.date);
post_list.retain(|post| post.metadata.published); post_list.retain(|post| post.metadata.published);
@ -60,7 +55,6 @@ pub async fn render_blog_post_list(
title: "Posts".to_owned(), title: "Posts".to_owned(),
posts, posts,
tag, tag,
site_footer,
header_props, header_props,
}) })
} }

View File

@ -1,17 +1,13 @@
use askama::Template; use askama::Template;
use axum::{extract::Path, http::StatusCode}; use axum::{extract::Path, http::StatusCode};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use tokio::try_join;
use crate::{ use crate::{
blog_posts::blog_post_model::BlogPostMetadata, components::site_header::Link, filters, blog_posts::blog_post_model::BlogPostMetadata, components::site_header::Link, filters,
post_utils::post_parser::parse_post, post_utils::post_parser::parse_post,
}; };
use crate::components::{ use crate::components::site_header::HeaderProps;
site_footer::{render_site_footer, SiteFooter},
site_header::HeaderProps,
};
#[derive(Template)] #[derive(Template)]
#[template(path = "blog_post.html")] #[template(path = "blog_post.html")]
@ -20,21 +16,19 @@ pub struct BlogPostTemplate {
pub body: String, pub body: String,
pub date: DateTime<Utc>, pub date: DateTime<Utc>,
pub tags: Vec<String>, pub tags: Vec<String>,
pub site_footer: SiteFooter,
pub header_props: HeaderProps, pub header_props: HeaderProps,
} }
pub async fn render_blog_post(Path(post_id): Path<String>) -> Result<BlogPostTemplate, StatusCode> { pub async fn render_blog_post(Path(post_id): Path<String>) -> Result<BlogPostTemplate, StatusCode> {
let path = format!("../_posts/blog/{}.md", post_id); let path = format!("../_posts/blog/{}.md", post_id);
let parse_post = parse_post::<BlogPostMetadata>(&path); let parse_post = parse_post::<BlogPostMetadata>(&path);
let (site_footer, parsed) = try_join!(render_site_footer(), parse_post)?; let parsed = parse_post.await?;
Ok(BlogPostTemplate { Ok(BlogPostTemplate {
title: parsed.metadata.title, title: parsed.metadata.title,
date: parsed.metadata.date, date: parsed.metadata.date,
tags: parsed.metadata.tags, tags: parsed.metadata.tags,
body: parsed.body, body: parsed.body,
site_footer,
header_props: HeaderProps::with_back_link(Link { header_props: HeaderProps::with_back_link(Link {
href: "/blog".to_string(), href: "/blog".to_string(),
label: "All posts".to_string(), label: "All posts".to_string(),

View File

@ -1,10 +1,7 @@
use askama::Template; use askama::Template;
use axum::http::StatusCode; use axum::http::StatusCode;
use crate::components::{ use crate::components::site_header::HeaderProps;
site_footer::{render_site_footer, SiteFooter},
site_header::HeaderProps,
};
pub struct ContactLink { pub struct ContactLink {
pub href: String, pub href: String,
@ -17,13 +14,11 @@ pub struct ContactLink {
#[template(path = "contact.html")] #[template(path = "contact.html")]
pub struct ContactPageTemplate { pub struct ContactPageTemplate {
pub title: String, pub title: String,
pub site_footer: SiteFooter,
pub header_props: HeaderProps, pub header_props: HeaderProps,
pub links: Vec<ContactLink>, pub links: Vec<ContactLink>,
} }
pub async fn render_contact() -> Result<ContactPageTemplate, StatusCode> { pub async fn render_contact() -> Result<ContactPageTemplate, StatusCode> {
let site_footer = render_site_footer().await?;
let links = vec![ let links = vec![
ContactLink { ContactLink {
href: "mailto: michalvankosk@gmail.com".to_string(), href: "mailto: michalvankosk@gmail.com".to_string(),
@ -77,7 +72,6 @@ pub async fn render_contact() -> Result<ContactPageTemplate, StatusCode> {
Ok(ContactPageTemplate { Ok(ContactPageTemplate {
title: "Contact".to_owned(), title: "Contact".to_owned(),
site_footer,
header_props: HeaderProps::default(), header_props: HeaderProps::default(),
links, links,
}) })

View File

@ -7,10 +7,7 @@ use crate::{
blog_post_model::BlogPostMetadata, featured_blog_posts::get_featured_blog_posts, blog_post_model::BlogPostMetadata, featured_blog_posts::get_featured_blog_posts,
tag_list::get_popular_blog_tags, tag_list::get_popular_blog_tags,
}, },
components::{ components::site_header::HeaderProps,
site_footer::{render_site_footer, SiteFooter},
site_header::HeaderProps,
},
filters, filters,
post_utils::post_parser::ParseResult, post_utils::post_parser::ParseResult,
projects::{featured_projects::get_featured_projects, project_model::ProjectMetadata}, projects::{featured_projects::get_featured_projects, project_model::ProjectMetadata},
@ -19,7 +16,6 @@ use crate::{
#[derive(Template)] #[derive(Template)]
#[template(path = "index.html")] #[template(path = "index.html")]
pub struct IndexTemplate { pub struct IndexTemplate {
site_footer: SiteFooter,
header_props: HeaderProps, header_props: HeaderProps,
blog_tags: Vec<String>, blog_tags: Vec<String>,
featured_blog_posts: Vec<ParseResult<BlogPostMetadata>>, featured_blog_posts: Vec<ParseResult<BlogPostMetadata>>,
@ -27,15 +23,13 @@ pub struct IndexTemplate {
} }
pub async fn render_index() -> Result<IndexTemplate, StatusCode> { pub async fn render_index() -> Result<IndexTemplate, StatusCode> {
let (site_footer, blog_tags, featured_blog_posts, featured_projects) = try_join!( let (blog_tags, featured_blog_posts, featured_projects) = try_join!(
render_site_footer(),
get_popular_blog_tags(), get_popular_blog_tags(),
get_featured_blog_posts(), get_featured_blog_posts(),
get_featured_projects() get_featured_projects()
)?; )?;
Ok(IndexTemplate { Ok(IndexTemplate {
site_footer,
header_props: HeaderProps::default(), header_props: HeaderProps::default(),
blog_tags, blog_tags,
featured_blog_posts, featured_blog_posts,