diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/blog.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/blog.rs b/src/blog.rs index e549fb2..6bbda49 100644 --- a/src/blog.rs +++ b/src/blog.rs @@ -3,8 +3,9 @@ use sailfish::TemplateOnce; use chrono::NaiveDate; use regex::{Regex}; use std::str; +use std::cmp::{PartialOrd, Ord, PartialEq, Eq}; -const BLOG_REGEX: &str = r"(?P<date>[\d]{4}-[\d]{2}-[\d]{2})(?P<title>[a-zA-Z0-9_]*)"; +const BLOG_REGEX: &str = r"(?P<date>[\d]{4}-[\d]{2}-[\d]{2})(?P<title>[a-zA-Z0-9-_]*)"; #[derive(RustEmbed)] #[folder = "content/posts/"] @@ -25,6 +26,7 @@ struct PostTemplate { date: String } +#[derive(PartialEq, Eq, PartialOrd, Ord)] pub struct BlogEntry { pub title: String, pub datetime: NaiveDate, @@ -46,10 +48,15 @@ impl BlogEntry { } pub fn read_assets() -> Vec<BlogEntry> { - PostAsset::iter() + + let mut entries: Vec<BlogEntry> = PostAsset::iter() .map(|e| format!("{}", e)) .map(|e| BlogEntry::new(&e)) - .collect() + .collect(); + + entries.sort_by(|a, b| b.datetime.cmp(&a.datetime)); + + entries } } |