2024-10-02 15:32:40 +02:00
|
|
|
use axum::{
|
|
|
|
extract::{OriginalUri, Path},
|
|
|
|
http::StatusCode,
|
|
|
|
};
|
|
|
|
use tokio::try_join;
|
|
|
|
use tracing::debug;
|
|
|
|
|
|
|
|
use crate::{
|
2024-10-07 10:08:56 +02:00
|
|
|
blog_posts::blog_post_model::{BlogPostMetadata, Segment, BLOG_POST_PATH},
|
2024-10-02 15:32:40 +02:00
|
|
|
components::site_header::{HeaderProps, Link},
|
2024-10-03 14:59:28 +02:00
|
|
|
post_utils::{
|
|
|
|
post_listing::get_post_list,
|
2024-10-07 10:08:56 +02:00
|
|
|
segments::get_posts_by_segment,
|
2024-10-03 14:59:28 +02:00
|
|
|
tags::{get_popular_tags, get_posts_by_tag},
|
|
|
|
},
|
2024-10-02 15:32:40 +02:00
|
|
|
projects::featured_projects::get_featured_projects,
|
|
|
|
};
|
|
|
|
|
2024-10-03 14:59:28 +02:00
|
|
|
use super::post_list::PostListTemplate;
|
2024-10-02 15:32:40 +02:00
|
|
|
|
|
|
|
pub async fn render_broadcast_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);
|
|
|
|
|
2024-10-07 10:08:56 +02:00
|
|
|
let (popular_tags, featured_projects, post_list) = try_join!(
|
|
|
|
get_popular_tags(Some(Segment::Broadcasts)),
|
2024-10-02 15:32:40 +02:00
|
|
|
get_featured_projects(),
|
|
|
|
get_post_list::<BlogPostMetadata>(BLOG_POST_PATH)
|
|
|
|
)?;
|
|
|
|
|
2024-10-07 10:08:56 +02:00
|
|
|
let posts = get_posts_by_segment(post_list, &[Segment::Broadcasts]);
|
|
|
|
let posts = get_posts_by_tag(posts, &tag);
|
2024-10-02 15:32:40 +02:00
|
|
|
|
|
|
|
let header_props = match tag {
|
|
|
|
Some(_) => HeaderProps::with_back_link(Link {
|
|
|
|
href: "/broadcasts".to_string(),
|
|
|
|
label: "All broadcasts".to_string(),
|
|
|
|
}),
|
|
|
|
None => HeaderProps::default(),
|
|
|
|
};
|
|
|
|
|
|
|
|
debug!("uri:{:?}", original_uri);
|
|
|
|
|
|
|
|
let title = if let Some(tag) = &tag {
|
|
|
|
format!("#{tag} broadcasts")
|
|
|
|
} else {
|
|
|
|
"Broadcasts".to_string()
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(PostListTemplate {
|
|
|
|
title: title.clone(),
|
|
|
|
og_title: title,
|
2024-10-07 10:08:56 +02:00
|
|
|
segment: Segment::Broadcasts,
|
2024-10-02 15:32:40 +02:00
|
|
|
posts,
|
|
|
|
header_props,
|
|
|
|
tags: popular_tags,
|
|
|
|
featured_projects,
|
|
|
|
current_url: original_uri.to_string(),
|
|
|
|
})
|
|
|
|
}
|