From 8b6dbc83c7538d43b93e0766cecc0680a0a9be1e Mon Sep 17 00:00:00 2001 From: Michal Vanko Date: Thu, 25 Jul 2024 22:38:00 +0200 Subject: [PATCH] change the asynchronity --- axum_server/src/pages/contact.rs | 5 +---- axum_server/src/pages/index.rs | 3 +-- axum_server/src/pages/post.rs | 8 +++----- axum_server/src/pages/post_list.rs | 6 +----- axum_server/styles/output.css | 12 ++++++------ axum_server/templates/post_preview_card.html | 2 +- 6 files changed, 13 insertions(+), 23 deletions(-) diff --git a/axum_server/src/pages/contact.rs b/axum_server/src/pages/contact.rs index 7d7e5f6..cb0f160 100644 --- a/axum_server/src/pages/contact.rs +++ b/axum_server/src/pages/contact.rs @@ -23,10 +23,7 @@ pub struct ContactPageTemplate { } pub async fn render_contact() -> Result { - let site_footer = tokio::spawn(render_site_footer()); - let site_footer = site_footer - .await - .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; + let site_footer = render_site_footer().await?; let links = vec![ ContactLink { href: "mailto: michalvankosk@gmail.com".to_string(), diff --git a/axum_server/src/pages/index.rs b/axum_server/src/pages/index.rs index 1148599..cc7ec97 100644 --- a/axum_server/src/pages/index.rs +++ b/axum_server/src/pages/index.rs @@ -33,8 +33,7 @@ pub async fn render_index() -> Result { get_popular_blog_tags(), get_featured_posts(), get_featured_projects() - ) - .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; + )?; Ok(IndexTemplate { site_footer, diff --git a/axum_server/src/pages/post.rs b/axum_server/src/pages/post.rs index b98484e..f7d54e5 100644 --- a/axum_server/src/pages/post.rs +++ b/axum_server/src/pages/post.rs @@ -3,6 +3,7 @@ use askama::Template; use axum::{extract::Path, http::StatusCode}; use chrono::{DateTime, Utc}; use serde::Deserialize; +use tokio::try_join; use crate::{ components::{ @@ -38,13 +39,10 @@ pub struct PostTemplate { } pub async fn render_post(Path(post_id): Path) -> Result { - let site_footer = tokio::spawn(render_site_footer()); let path = format!("../_posts/blog/{}.md", post_id); - let parsed = parse_post::(&path).await?; + let parse_post = parse_post::(&path); + let (site_footer, parsed) = try_join!(render_site_footer(), parse_post)?; - let site_footer = site_footer - .await - .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; Ok(PostTemplate { title: parsed.metadata.title, date: parsed.metadata.date, diff --git a/axum_server/src/pages/post_list.rs b/axum_server/src/pages/post_list.rs index 9352367..57a100b 100644 --- a/axum_server/src/pages/post_list.rs +++ b/axum_server/src/pages/post_list.rs @@ -27,7 +27,7 @@ pub async fn render_post_list(tag: Option>) -> Result(BLOG_POST_PATH).await?; post_list.sort_by_key(|post| post.metadata.date); post_list.reverse(); @@ -47,10 +47,6 @@ pub async fn render_post_list(tag: Option>) -> Result post_list, }; - let site_footer = site_footer - .await - .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; - let header_props = match tag { Some(_) => HeaderProps::with_back_link(Link { href: "/blog".to_string(), diff --git a/axum_server/styles/output.css b/axum_server/styles/output.css index 03151dc..320c219 100644 --- a/axum_server/styles/output.css +++ b/axum_server/styles/output.css @@ -1,5 +1,5 @@ /* -! tailwindcss v3.4.6 | MIT License | https://tailwindcss.com +! tailwindcss v3.4.7 | MIT License | https://tailwindcss.com */ /* @@ -604,6 +604,11 @@ video { margin-bottom: 3rem; } +.my-2 { + margin-top: 0.5rem; + margin-bottom: 0.5rem; +} + .my-3 { margin-top: 0.75rem; margin-bottom: 0.75rem; @@ -619,11 +624,6 @@ video { margin-bottom: 1.5rem; } -.my-2 { - margin-top: 0.5rem; - margin-bottom: 0.5rem; -} - .mb-1 { margin-bottom: 0.25rem; } diff --git a/axum_server/templates/post_preview_card.html b/axum_server/templates/post_preview_card.html index eb96288..fb086ed 100644 --- a/axum_server/templates/post_preview_card.html +++ b/axum_server/templates/post_preview_card.html @@ -4,7 +4,7 @@ {{post.metadata.title}}