aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-11-03 19:55:25 -0800
committerFuwn <[email protected]>2024-11-03 19:55:25 -0800
commitfe632058c09a892f23a370f33b992485ed1212f2 (patch)
tree86225584211b305555fa1a5c9008109dea1bc206 /src
parentchore(flake): pin openssl (diff)
downloadlocus-fe632058c09a892f23a370f33b992485ed1212f2.tar.xz
locus-fe632058c09a892f23a370f33b992485ed1212f2.zip
feat(blog): priority field
Diffstat (limited to 'src')
-rw-r--r--src/modules/blog/config.rs10
-rw-r--r--src/modules/blog/module.rs21
2 files changed, 26 insertions, 5 deletions
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<String>,
description: Option<String>,
posts: Option<HashMap<String, Entry>>,
+ priority: Option<u8>,
}
impl Blog {
pub const fn description(&self) -> &Option<String> { &self.description }
@@ -35,6 +37,8 @@ impl Blog {
pub const fn posts(&self) -> &Option<HashMap<String, Entry>> { &self.posts }
+ pub const fn priority(&self) -> &Option<u8> { &self.priority }
+
pub fn from_string(string: &str) -> serde_json::Result<Self> {
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::<Vec<(_, _)>>()
.into_iter()
.map(|(title, entries)| {