diff --git a/_posts/blog/2021-05-07-introduction-javascript-to-javascript-application-testing.md b/_posts/blog/2021-05-07-introduction-javascript-to-javascript-application-testing.md index 6adb6c4..7aaf70a 100644 --- a/_posts/blog/2021-05-07-introduction-javascript-to-javascript-application-testing.md +++ b/_posts/blog/2021-05-07-introduction-javascript-to-javascript-application-testing.md @@ -3,6 +3,7 @@ layout: blog title: Introduction to JavaScript Application testing segments: - blog + - featured published: true date: 2021-05-07T14:44:57.102Z # update date accordingly tags: diff --git a/_posts/blog/2023-02-04-devbreak-5-joys-and-concerns-of-engineering-manager.md b/_posts/blog/2023-02-04-devbreak-5-joys-and-concerns-of-engineering-manager.md index c927a0f..752080e 100644 --- a/_posts/blog/2023-02-04-devbreak-5-joys-and-concerns-of-engineering-manager.md +++ b/_posts/blog/2023-02-04-devbreak-5-joys-and-concerns-of-engineering-manager.md @@ -3,6 +3,7 @@ layout: blog title: "DevBreak #5 Joys and concerns of Engineering manager with Pavol Dudrík" segments: - broadcasts + - featured published: true date: 2023-02-04T20:22:21.191Z thumbnail: /images/uploads/devbreak.jpeg diff --git a/src/blog_posts/blog_post_model.rs b/src/blog_posts/blog_post_model.rs index a41021c..60addee 100644 --- a/src/blog_posts/blog_post_model.rs +++ b/src/blog_posts/blog_post_model.rs @@ -5,7 +5,7 @@ use crate::post_utils::post_parser::deserialize_date; pub const BLOG_POST_PATH: &str = "_posts/blog"; -#[derive(Deserialize, Debug)] +#[derive(Deserialize, Debug, Clone)] pub struct BlogPostMetadata { pub title: String, pub segments: Vec, diff --git a/src/blog_posts/featured_blog_posts.rs b/src/blog_posts/featured_blog_posts.rs deleted file mode 100644 index 207f28d..0000000 --- a/src/blog_posts/featured_blog_posts.rs +++ /dev/null @@ -1,15 +0,0 @@ -use axum::http::StatusCode; - -use crate::post_utils::{post_listing::get_post_list, post_parser::ParseResult}; - -use super::blog_post_model::{BlogPostMetadata, BLOG_POST_PATH}; - -pub async fn get_featured_blog_posts() -> Result>, StatusCode> { - let mut post_list = get_post_list::(BLOG_POST_PATH).await?; - post_list.retain(|post| post.metadata.segments.contains(&"featured".to_string())); - post_list.retain(|post| post.metadata.published); - post_list.sort_by_key(|post| post.metadata.date); - post_list.reverse(); - - Ok(post_list) -} diff --git a/src/blog_posts/mod.rs b/src/blog_posts/mod.rs index 2efd6bc..0abe542 100644 --- a/src/blog_posts/mod.rs +++ b/src/blog_posts/mod.rs @@ -1,2 +1 @@ pub mod blog_post_model; -pub mod featured_blog_posts; diff --git a/src/pages/index.rs b/src/pages/index.rs index 77660d6..d151f81 100644 --- a/src/pages/index.rs +++ b/src/pages/index.rs @@ -1,12 +1,17 @@ +use std::rc::Rc; + use askama::Template; use axum::http::StatusCode; use tokio::try_join; use crate::{ - blog_posts::{blog_post_model::BlogPostMetadata, featured_blog_posts::get_featured_blog_posts}, + blog_posts::blog_post_model::{BlogPostMetadata, BLOG_POST_PATH}, components::site_header::HeaderProps, filters, - post_utils::{post_parser::ParseResult, tags::get_popular_tags}, + post_utils::{ + post_listing::get_post_list, post_parser::ParseResult, segments::ref_get_posts_by_segment, + tags::get_popular_tags, + }, projects::{featured_projects::get_featured_projects, project_model::ProjectMetadata}, }; @@ -15,21 +20,38 @@ use crate::{ pub struct IndexTemplate { header_props: HeaderProps, blog_tags: Vec, - featured_blog_posts: Vec>, + broadcasts_tags: Vec, + featured_blog_posts: Vec>>, featured_projects: Vec>, + featured_broadcasts: Vec>>, } pub async fn render_index() -> Result { - let (blog_tags, featured_blog_posts, featured_projects) = try_join!( + let (blog_tags, broadcasts_tags, all_posts, featured_projects) = try_join!( get_popular_tags(Some("blog".to_string())), - get_featured_blog_posts(), + get_popular_tags(Some("broadcasts".to_string())), + get_post_list::(BLOG_POST_PATH), get_featured_projects() )?; + // Convert the all_posts into Rc> + let all_posts_rc: Vec>> = + all_posts.into_iter().map(Rc::new).collect(); + + let featured_blog_posts = + ref_get_posts_by_segment(&all_posts_rc, &["blog".to_string(), "featured".to_string()]); + + let featured_broadcasts = ref_get_posts_by_segment( + &all_posts_rc, + &["broadcasts".to_string(), "featured".to_string()], + ); + Ok(IndexTemplate { header_props: HeaderProps::default(), blog_tags, + broadcasts_tags, featured_blog_posts, featured_projects, + featured_broadcasts, }) } diff --git a/src/post_utils/mod.rs b/src/post_utils/mod.rs index 0629f5a..fcf4d3f 100644 --- a/src/post_utils/mod.rs +++ b/src/post_utils/mod.rs @@ -1,3 +1,4 @@ pub mod post_listing; pub mod post_parser; +pub mod segments; pub mod tags; diff --git a/src/post_utils/post_parser.rs b/src/post_utils/post_parser.rs index bdc0c79..8605100 100644 --- a/src/post_utils/post_parser.rs +++ b/src/post_utils/post_parser.rs @@ -32,6 +32,7 @@ where } } +#[derive(Clone)] pub struct ParseResult { pub body: String, pub metadata: Metadata, diff --git a/src/post_utils/segments.rs b/src/post_utils/segments.rs new file mode 100644 index 0000000..b47de68 --- /dev/null +++ b/src/post_utils/segments.rs @@ -0,0 +1,51 @@ +use std::rc::Rc; + +use crate::blog_posts::blog_post_model::BlogPostMetadata; + +use super::post_parser::ParseResult; + +// // TODO convert segmetns to enum, find out how to serde to enum vlaue +// pub fn get_posts_by_segment( +// post_list: &Vec>, +// segments: &Vec, +// ) -> Vec> { +// let mut filtered_posts: Vec> = post_list +// .iter() +// .filter(|post| { +// segments +// .iter() +// .all(|segment| post.metadata.segments.contains(segment)) +// }) // Filter by segments +// .filter(|post| post.metadata.published) // Filter only published posts +// .cloned() +// .collect(); + +// // Sort by date in descending order +// filtered_posts.sort_by_key(|post| post.metadata.date); +// filtered_posts.reverse(); + +// filtered_posts +// } + +pub fn ref_get_posts_by_segment( + post_list: &[Rc>], + segments: &[String], +) -> Vec>> { + let mut filtered_posts: Vec>> = post_list + .iter() // Use iter() to borrow instead of consuming the original vector + .filter(|post| { + let post = post.as_ref(); + segments + .iter() + .all(|segment| post.metadata.segments.contains(segment)) + }) // Filter by segments + .filter(|post| post.metadata.published) // Filter only published posts + .cloned() + .collect(); // Collect references to ParseResult + + // Sort by date in descending order + filtered_posts.sort_by_key(|post| post.metadata.date); + filtered_posts.reverse(); + + filtered_posts +} diff --git a/templates/index.html b/templates/index.html index e6ed2e7..81c084a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -76,6 +76,33 @@
{% include "sections/showcase.html" %}
+ +
+ {% let segment = "broadcasts".to_string() %} +

Broadcasts

+
+ +
+
+ +
    + {% for post in featured_broadcasts %} +
  • + {% include "components/blog_post_preview.html" %} +
    +
  • + {% endfor %} +
+
+ see all broadcasts +
+