site_footer and post listing order

This commit is contained in:
2024-01-18 22:33:36 +01:00
parent e0ad3f29ae
commit c9704a20f6
9 changed files with 108 additions and 38 deletions

View File

@ -0,0 +1 @@
pub mod site_footer;

View File

@ -0,0 +1,21 @@
use askama::Template;
use crate::{pages::post::PostMetadata, post_list::get_post_list, post_parser::ParseResult};
#[derive(Template)]
#[template(path = "site_footer.html")]
pub struct SiteFooter {
pub latest_posts: Vec<ParseResult<PostMetadata>>,
}
pub async fn render_site_footer() -> SiteFooter {
let mut post_list = get_post_list::<PostMetadata>().await.unwrap_or(vec![]);
post_list.sort_by_key(|post| post.metadata.date);
post_list.reverse();
let latest_posts = post_list
.into_iter()
.take(6)
.collect::<Vec<ParseResult<PostMetadata>>>();
SiteFooter { latest_posts }
}