From fe632058c09a892f23a370f33b992485ed1212f2 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 3 Nov 2024 19:55:25 -0800 Subject: feat(blog): priority field --- content/blogs/finger_archive/blog.json | 3 ++- content/blogs/news/blog.json | 3 ++- content/blogs/technology/blog.json | 3 ++- content/blogs/the_daily/blog.json | 3 ++- src/modules/blog/config.rs | 10 +++++++--- src/modules/blog/module.rs | 21 +++++++++++++++++++-- 6 files changed, 34 insertions(+), 9 deletions(-) diff --git a/content/blogs/finger_archive/blog.json b/content/blogs/finger_archive/blog.json index a247bcf..2148303 100644 --- a/content/blogs/finger_archive/blog.json +++ b/content/blogs/finger_archive/blog.json @@ -1,4 +1,5 @@ { + "priority": 2, "posts": { "2024_06_27": { "name": "June 27th, 2024" @@ -7,4 +8,4 @@ "name": "June 29th, 2024" } } -} +} \ No newline at end of file diff --git a/content/blogs/news/blog.json b/content/blogs/news/blog.json index ddbfbad..181335d 100644 --- a/content/blogs/news/blog.json +++ b/content/blogs/news/blog.json @@ -1,4 +1,5 @@ { + "priority": 1, "description": "The [Inconsistently Updated] Update Log of This Gemini Capsule", "posts": {} -} +} \ No newline at end of file diff --git a/content/blogs/technology/blog.json b/content/blogs/technology/blog.json index efbfcfe..d58ec59 100644 --- a/content/blogs/technology/blog.json +++ b/content/blogs/technology/blog.json @@ -1,4 +1,5 @@ { + "priority": 3, "description": "Thoughts and Resources of the Programming Languages and Technologies I Actively Use and Have Used", "posts": { "Go": { @@ -22,4 +23,4 @@ "last_modified": "2021. 07. 23." } } -} +} \ No newline at end of file diff --git a/content/blogs/the_daily/blog.json b/content/blogs/the_daily/blog.json index 14d39c8..fc7bfb5 100644 --- a/content/blogs/the_daily/blog.json +++ b/content/blogs/the_daily/blog.json @@ -1,4 +1,5 @@ { + "priority": 0, "description": null, "posts": { "nvme_troubles_part_1": { @@ -30,4 +31,4 @@ "name": "The AirPods 4 with ANC are impressive!" } } -} +} \ No newline at end of file diff --git a/src/modules/blog/config.rs b/src/modules/blog/config.rs index 20c3bd4..c2e4cc9 100644 --- a/src/modules/blog/config.rs +++ b/src/modules/blog/config.rs @@ -1,6 +1,7 @@ -use std::collections::HashMap; - -use serde::{Deserialize, Serialize}; +use { + serde::{Deserialize, Serialize}, + std::collections::HashMap, +}; #[derive(Serialize, Deserialize, Clone, Default)] pub struct Entry { @@ -27,6 +28,7 @@ pub struct Blog { name: Option, description: Option, posts: Option>, + priority: Option, } impl Blog { pub const fn description(&self) -> &Option { &self.description } @@ -35,6 +37,8 @@ impl Blog { pub const fn posts(&self) -> &Option> { &self.posts } + pub const fn priority(&self) -> &Option { &self.priority } + pub fn from_string(string: &str) -> serde_json::Result { serde_json::from_str(string) } diff --git a/src/modules/blog/module.rs b/src/modules/blog/module.rs index e6fcd06..bfab002 100644 --- a/src/modules/blog/module.rs +++ b/src/modules/blog/module.rs @@ -80,7 +80,24 @@ pub fn module(router: &mut windmark::router::Router) { ); } - let blog_clone = blogs.clone(); + let mut blog_clone: Vec<_> = blogs + .clone() + .into_iter() + .map(|(blog, entries)| { + ( + blog, + *entries + .get("blog.json") + .and_then(|content| Blog::from_string(content).ok()) + .unwrap_or_default() + .priority(), + entries, + ) + }) + .collect(); + + blog_clone.sort_by(|a, b| b.1.cmp(&a.1)); + blog_clone.reverse(); track_mount(router, "/blog", "Fuwn's blogs", move |context| { success( @@ -89,7 +106,7 @@ pub fn module(router: &mut windmark::router::Router) { blog_clone.len(), blog_clone .iter() - .map(|(title, entries)| (title.clone(), entries.clone())) + .map(|(title, _, entries)| (title.clone(), entries.clone())) .collect::>() .into_iter() .map(|(title, entries)| { -- cgit v1.2.3