aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2022-05-15 15:34:36 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2022-05-15 15:34:36 +0200
commit231f2cb2205988cf87062bc9f595307af1ed827f (patch)
treef1094bf50677abed5266feb17c65240a45d7a387 /src
parent46e6b5fa84b1ec6e08f124c478909ec745562214 (diff)
downloadmacroblog.rs-231f2cb2205988cf87062bc9f595307af1ed827f.tar.gz
macroblog.rs-231f2cb2205988cf87062bc9f595307af1ed827f.tar.bz2
macroblog.rs-231f2cb2205988cf87062bc9f595307af1ed827f.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/blog.rs13
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
}
}