diff options
| author | Fuwn <[email protected]> | 2024-11-03 23:14:38 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-11-03 23:14:38 -0800 |
| commit | f8fabd790748925e8d27ad3408a147b7edd531f4 (patch) | |
| tree | 81c4cec2fbf3c6bc58bde6695da845f43b976b46 /src/modules/blog/module.rs | |
| parent | feat(blog): priority field (diff) | |
| download | locus-f8fabd790748925e8d27ad3408a147b7edd531f4.tar.xz locus-f8fabd790748925e8d27ad3408a147b7edd531f4.zip | |
feat(index): add recent posts section
Diffstat (limited to 'src/modules/blog/module.rs')
| -rw-r--r-- | src/modules/blog/module.rs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/modules/blog/module.rs b/src/modules/blog/module.rs index bfab002..71b3a46 100644 --- a/src/modules/blog/module.rs +++ b/src/modules/blog/module.rs @@ -1,4 +1,5 @@ use { + super::post::Post, crate::{ modules::blog::config::Blog, response::success, @@ -10,9 +11,13 @@ use { collections::HashMap, fs::{self, read_dir}, io::Read, + sync::{LazyLock, Mutex}, }, }; +pub static POSTS: LazyLock<Mutex<Vec<Post>>> = + LazyLock::new(|| Mutex::new(Vec::new())); + #[allow(clippy::too_many_lines)] pub fn module(router: &mut windmark::router::Router) { let paths = read_dir("content/blogs").unwrap(); @@ -239,6 +244,7 @@ pub fn module(router: &mut windmark::router::Router) { .unwrap_or_else(|()| (String::new(), String::new())); let fixed_blog_name = fixed_blog_name_clone_2.clone(); let mut real_title = "Unknown"; + let mut created = ""; xml.add_item(&{ let mut builder = XmlItem::builder(); @@ -270,6 +276,8 @@ pub fn module(router: &mut windmark::router::Router) { if let Some(date) = post.created() { builder.add_field("pubDate", date); + + created = date; } } } @@ -280,13 +288,20 @@ pub fn module(router: &mut windmark::router::Router) { builder }); + let link = format!("/blog/{}/{}", fixed_blog_name, title.to_lowercase()); + let title = format!("{name}, {real_title}"); + + (*POSTS.lock().unwrap()).push(Post::new( + title.clone(), + link.clone(), + created.to_string(), + )); track_mount( router, - &format!("/blog/{}/{}", fixed_blog_name, title.to_lowercase()), + &link, &format!( - "{}, {} ― {}", - name, - real_title, + "{} ― {}", + title, if header.1.is_empty() { "An entry to one of Fuwn's blogs".to_string() } else { |