add og tags
Some checks failed
test / cargo test (push) Failing after 1m26s

This commit is contained in:
2024-10-01 21:02:19 +02:00
parent da78b80587
commit 49f830cd44
11 changed files with 150 additions and 7 deletions

View File

@ -1,6 +1,10 @@
use askama::Template;
use axum::{extract::Path, http::StatusCode};
use axum::{
extract::{OriginalUri, Path, RawQuery},
http::StatusCode,
};
use tokio::try_join;
use tracing::debug;
use crate::{
blog_posts::{
@ -22,10 +26,12 @@ pub struct PostListTemplate {
pub header_props: HeaderProps,
pub blog_tags: Vec<String>,
pub featured_projects: Vec<ParseResult<ProjectMetadata>>,
pub current_url: String,
}
pub async fn render_blog_post_list(
tag: Option<Path<String>>,
OriginalUri(original_uri): OriginalUri,
) -> Result<PostListTemplate, StatusCode> {
// I will forget what happens here in a week. But essentially it's pattern matching and shadowing
let tag = tag.map(|Path(tag)| tag);
@ -63,12 +69,21 @@ pub async fn render_blog_post_list(
None => HeaderProps::default(),
};
debug!("uri:{:?}", original_uri);
let title = if let Some(tag) = &tag {
format!("{tag} blog posts")
} else {
"Blog posts".to_string()
};
Ok(PostListTemplate {
title: "Blog posts".to_owned(),
title,
posts,
tag,
header_props,
blog_tags,
featured_projects,
current_url: original_uri.to_string(),
})
}

View File

@ -18,6 +18,8 @@ pub struct BlogPostTemplate {
pub date: DateTime<Utc>,
pub tags: Vec<String>,
pub header_props: HeaderProps,
pub slug: String,
pub thumbnail: Option<String>,
}
pub async fn render_blog_post(Path(post_id): Path<String>) -> Result<BlogPostTemplate, StatusCode> {
@ -30,6 +32,8 @@ pub async fn render_blog_post(Path(post_id): Path<String>) -> Result<BlogPostTem
date: parsed.metadata.date,
tags: parsed.metadata.tags,
body: parsed.body,
slug: parsed.slug,
thumbnail: parsed.metadata.thumbnail,
header_props: HeaderProps::with_back_link(Link {
href: "/blog".to_string(),
label: "All posts".to_string(),