change the asynchronity

This commit is contained in:
Michal Vanko 2024-07-25 22:38:00 +02:00
parent 754a115043
commit 8b6dbc83c7
6 changed files with 13 additions and 23 deletions

View File

@ -23,10 +23,7 @@ pub struct ContactPageTemplate {
} }
pub async fn render_contact() -> Result<ContactPageTemplate, StatusCode> { pub async fn render_contact() -> Result<ContactPageTemplate, StatusCode> {
let site_footer = tokio::spawn(render_site_footer()); let site_footer = render_site_footer().await?;
let site_footer = site_footer
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let links = vec![ let links = vec![
ContactLink { ContactLink {
href: "mailto: michalvankosk@gmail.com".to_string(), href: "mailto: michalvankosk@gmail.com".to_string(),

View File

@ -33,8 +33,7 @@ pub async fn render_index() -> Result<IndexTemplate, StatusCode> {
get_popular_blog_tags(), get_popular_blog_tags(),
get_featured_posts(), get_featured_posts(),
get_featured_projects() get_featured_projects()
) )?;
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
Ok(IndexTemplate { Ok(IndexTemplate {
site_footer, site_footer,

View File

@ -3,6 +3,7 @@ use askama::Template;
use axum::{extract::Path, http::StatusCode}; use axum::{extract::Path, http::StatusCode};
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use serde::Deserialize; use serde::Deserialize;
use tokio::try_join;
use crate::{ use crate::{
components::{ components::{
@ -38,13 +39,10 @@ pub struct PostTemplate {
} }
pub async fn render_post(Path(post_id): Path<String>) -> Result<PostTemplate, StatusCode> { pub async fn render_post(Path(post_id): Path<String>) -> Result<PostTemplate, StatusCode> {
let site_footer = tokio::spawn(render_site_footer());
let path = format!("../_posts/blog/{}.md", post_id); let path = format!("../_posts/blog/{}.md", post_id);
let parsed = parse_post::<PostMetadata>(&path).await?; let parse_post = parse_post::<PostMetadata>(&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 { Ok(PostTemplate {
title: parsed.metadata.title, title: parsed.metadata.title,
date: parsed.metadata.date, date: parsed.metadata.date,

View File

@ -27,7 +27,7 @@ pub async fn render_post_list(tag: Option<Path<String>>) -> Result<PostListTempl
// 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 = tokio::spawn(render_site_footer()); let site_footer = render_site_footer().await?;
let mut post_list = get_post_list::<PostMetadata>(BLOG_POST_PATH).await?; let mut post_list = get_post_list::<PostMetadata>(BLOG_POST_PATH).await?;
post_list.sort_by_key(|post| post.metadata.date); post_list.sort_by_key(|post| post.metadata.date);
post_list.reverse(); post_list.reverse();
@ -47,10 +47,6 @@ pub async fn render_post_list(tag: Option<Path<String>>) -> Result<PostListTempl
None => post_list, None => post_list,
}; };
let site_footer = site_footer
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let header_props = match tag { let header_props = match tag {
Some(_) => HeaderProps::with_back_link(Link { Some(_) => HeaderProps::with_back_link(Link {
href: "/blog".to_string(), href: "/blog".to_string(),

View File

@ -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; margin-bottom: 3rem;
} }
.my-2 {
margin-top: 0.5rem;
margin-bottom: 0.5rem;
}
.my-3 { .my-3 {
margin-top: 0.75rem; margin-top: 0.75rem;
margin-bottom: 0.75rem; margin-bottom: 0.75rem;
@ -619,11 +624,6 @@ video {
margin-bottom: 1.5rem; margin-bottom: 1.5rem;
} }
.my-2 {
margin-top: 0.5rem;
margin-bottom: 0.5rem;
}
.mb-1 { .mb-1 {
margin-bottom: 0.25rem; margin-bottom: 0.25rem;
} }

View File

@ -4,7 +4,7 @@
<a rel="prefetch" href="/blog/{{post.slug}}">{{post.metadata.title}}</a> <a rel="prefetch" href="/blog/{{post.slug}}">{{post.metadata.title}}</a>
</h2> </h2>
<aside class="flex justify-between"> <aside class="flex justify-between">
{% let tags = post.metadata.tags %} {% let tags = post.metadata.tags.clone() %}
{% include "post_tag_list.html" %} {% include "post_tag_list.html" %}
<section class="created-at m-1 text-right text-sm text-gray-600"> <section class="created-at m-1 text-right text-sm text-gray-600">
<span>Published on</span> <span>Published on</span>