aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-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)| {