From 231f2cb2205988cf87062bc9f595307af1ed827f Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sun, 15 May 2022 15:34:36 +0200 Subject: feat: Add missing blog post Add the missing blog post from my hugo blog. Also add a locustfile so I can do some stress test locally. --- src/blog.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') 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[\d]{4}-[\d]{2}-[\d]{2})(?P[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 } } -- cgit v1.2.3