what a turn of events

This commit is contained in:
Michal Vanko 2024-07-23 15:08:29 +02:00
parent 1861a85e76
commit 754a115043
2 changed files with 13 additions and 26 deletions

View File

@ -1,4 +1,5 @@
use askama::Template; use askama::Template;
use axum::http::StatusCode;
use crate::{ use crate::{
pages::post::{PostMetadata, BLOG_POST_PATH}, pages::post::{PostMetadata, BLOG_POST_PATH},
@ -12,10 +13,9 @@ pub struct SiteFooter {
pub latest_posts: Vec<ParseResult<PostMetadata>>, pub latest_posts: Vec<ParseResult<PostMetadata>>,
} }
pub async fn render_site_footer() -> SiteFooter { // TODO remove whole site footer anyway
let mut post_list = get_post_list::<PostMetadata>(BLOG_POST_PATH) pub async fn render_site_footer() -> Result<SiteFooter, StatusCode> {
.await let mut post_list = get_post_list::<PostMetadata>(BLOG_POST_PATH).await?;
.unwrap_or(vec![]);
post_list.sort_by_key(|post| post.metadata.date); post_list.sort_by_key(|post| post.metadata.date);
post_list.reverse(); post_list.reverse();
@ -23,5 +23,5 @@ pub async fn render_site_footer() -> SiteFooter {
.into_iter() .into_iter()
.take(6) .take(6)
.collect::<Vec<ParseResult<PostMetadata>>>(); .collect::<Vec<ParseResult<PostMetadata>>>();
SiteFooter { latest_posts } Ok(SiteFooter { latest_posts })
} }

View File

@ -1,5 +1,6 @@
use askama::Template; use askama::Template;
use axum::http::StatusCode; use axum::http::StatusCode;
use tokio::try_join;
use crate::filters; use crate::filters;
use crate::{ use crate::{
@ -27,28 +28,14 @@ pub struct IndexTemplate {
} }
pub async fn render_index() -> Result<IndexTemplate, StatusCode> { pub async fn render_index() -> Result<IndexTemplate, StatusCode> {
let site_footer = tokio::spawn(render_site_footer()); let (site_footer, blog_tags, featured_posts, featured_projects) = try_join!(
let blog_tags = tokio::spawn(get_popular_blog_tags()); render_site_footer(),
let featured_posts = tokio::spawn(get_featured_posts()); get_popular_blog_tags(),
let featured_projects = tokio::spawn(get_featured_projects()); get_featured_posts(),
get_featured_projects()
let blog_tags = blog_tags )
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)??;
let site_footer = site_footer
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let featured_posts = featured_posts
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)??;
let featured_projects = featured_projects
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)??;
// TODO convert projects into cms
Ok(IndexTemplate { Ok(IndexTemplate {
site_footer, site_footer,
header_props: HeaderProps::default(), header_props: HeaderProps::default(),