This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use askama::Template;
|
||||
use axum::{
|
||||
extract::{OriginalUri, Path, RawQuery},
|
||||
extract::{OriginalUri, Path},
|
||||
http::StatusCode,
|
||||
};
|
||||
use tokio::try_join;
|
||||
@ -9,7 +9,7 @@ use tracing::debug;
|
||||
use crate::{
|
||||
blog_posts::{
|
||||
blog_post_model::{BlogPostMetadata, BLOG_POST_PATH},
|
||||
tag_list::get_popular_blog_tags,
|
||||
tag_list::{get_popular_tags, get_posts_by_tag},
|
||||
},
|
||||
components::site_header::{HeaderProps, Link},
|
||||
filters,
|
||||
@ -21,10 +21,11 @@ use crate::{
|
||||
#[template(path = "blog_post_list.html")]
|
||||
pub struct PostListTemplate {
|
||||
pub title: String,
|
||||
pub og_title: String,
|
||||
pub segment: String,
|
||||
pub posts: Vec<ParseResult<BlogPostMetadata>>,
|
||||
pub tag: Option<String>,
|
||||
pub header_props: HeaderProps,
|
||||
pub blog_tags: Vec<String>,
|
||||
pub tags: Vec<String>,
|
||||
pub featured_projects: Vec<ParseResult<ProjectMetadata>>,
|
||||
pub current_url: String,
|
||||
}
|
||||
@ -37,30 +38,17 @@ pub async fn render_blog_post_list(
|
||||
let tag = tag.map(|Path(tag)| tag);
|
||||
|
||||
let (blog_tags, featured_projects, mut post_list) = try_join!(
|
||||
get_popular_blog_tags(),
|
||||
get_popular_tags(Some("blog".to_string())),
|
||||
get_featured_projects(),
|
||||
get_post_list::<BlogPostMetadata>(BLOG_POST_PATH)
|
||||
)?;
|
||||
|
||||
post_list.sort_by_key(|post| post.metadata.date);
|
||||
post_list.retain(|post| post.metadata.published);
|
||||
post_list.retain(|post| post.metadata.segments.contains(&"blog".to_string()));
|
||||
post_list.reverse();
|
||||
|
||||
let posts = match &tag {
|
||||
Some(tag) => post_list
|
||||
.into_iter()
|
||||
.filter(|post| {
|
||||
post.metadata
|
||||
.tags
|
||||
.iter()
|
||||
.map(|post_tag| post_tag.to_lowercase())
|
||||
.collect::<String>()
|
||||
.contains(&tag.to_lowercase())
|
||||
})
|
||||
.collect(),
|
||||
None => post_list,
|
||||
};
|
||||
|
||||
let posts = get_posts_by_tag(post_list, &tag);
|
||||
let header_props = match tag {
|
||||
Some(_) => HeaderProps::with_back_link(Link {
|
||||
href: "/blog".to_string(),
|
||||
@ -71,18 +59,19 @@ pub async fn render_blog_post_list(
|
||||
|
||||
debug!("uri:{:?}", original_uri);
|
||||
|
||||
let title = if let Some(tag) = &tag {
|
||||
format!("{tag} blog posts")
|
||||
let (title, og_title) = if let Some(tag) = &tag {
|
||||
(format!("#{tag}"), format!("{tag} blog posts"))
|
||||
} else {
|
||||
"Blog posts".to_string()
|
||||
("Blog posts".to_string(), "Blog posts".to_string())
|
||||
};
|
||||
|
||||
Ok(PostListTemplate {
|
||||
title,
|
||||
og_title,
|
||||
segment: "blog".to_string(),
|
||||
posts,
|
||||
tag,
|
||||
header_props,
|
||||
blog_tags,
|
||||
tags: blog_tags,
|
||||
featured_projects,
|
||||
current_url: original_uri.to_string(),
|
||||
})
|
||||
|
Reference in New Issue
Block a user