broadcasts segments enum

This commit is contained in:
2024-10-07 10:08:56 +02:00
parent e04e4f6491
commit 08050baf98
8 changed files with 82 additions and 61 deletions

View File

@ -6,10 +6,11 @@ use tokio::try_join;
use tracing::debug;
use crate::{
blog_posts::blog_post_model::{BlogPostMetadata, BLOG_POST_PATH},
blog_posts::blog_post_model::{BlogPostMetadata, Segment, BLOG_POST_PATH},
components::site_header::{HeaderProps, Link},
post_utils::{
post_listing::get_post_list,
segments::get_posts_by_segment,
tags::{get_popular_tags, get_posts_by_tag},
},
projects::featured_projects::get_featured_projects,
@ -17,6 +18,7 @@ use crate::{
use super::post_list::PostListTemplate;
// TODO Refactor to render post list for the same broadcasts, blog and cookbook
pub async fn render_blog_post_list(
tag: Option<Path<String>>,
OriginalUri(original_uri): OriginalUri,
@ -24,18 +26,14 @@ pub async fn render_blog_post_list(
// 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 (blog_tags, featured_projects, mut post_list) = try_join!(
get_popular_tags(Some("blog".to_string())),
let (blog_tags, featured_projects, post_list) = try_join!(
get_popular_tags(Some(Segment::Blog)),
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 = get_posts_by_tag(post_list, &tag);
let posts = get_posts_by_segment(post_list, &[Segment::Blog]);
let posts = get_posts_by_tag(posts, &tag);
let header_props = match tag {
Some(_) => HeaderProps::with_back_link(Link {
href: "/blog".to_string(),
@ -55,7 +53,7 @@ pub async fn render_blog_post_list(
Ok(PostListTemplate {
title,
og_title,
segment: "blog".to_string(),
segment: Segment::Blog,
posts,
header_props,
tags: blog_tags,