diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-05-14 00:00:22 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-05-14 00:00:22 +0200 |
commit | 16ef06ffb363b6304d0d5269b30dedbdd07288df (patch) | |
tree | 38f80e13c5f20d669df04d146725968f423541b4 /src | |
parent | 2bf274de3fe814e3729deb9ca242df58f8936a49 (diff) | |
download | macroblog.rs-16ef06ffb363b6304d0d5269b30dedbdd07288df.tar.gz macroblog.rs-16ef06ffb363b6304d0d5269b30dedbdd07288df.tar.bz2 macroblog.rs-16ef06ffb363b6304d0d5269b30dedbdd07288df.zip |
feat: Add title parser
Add title parse so it yields a better post list.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index cabff0e..63a5386 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,10 +9,15 @@ use hyper::service::{make_service_fn, service_fn}; use sailfish::TemplateOnce; use ::router::Router; +struct PostEntry { + title: String, + file: String, +} + #[derive(TemplateOnce)] #[template(path = "index.html")] struct IndexTemplate { - posts: Vec<String>, + posts: Vec<PostEntry>, } #[derive(TemplateOnce)] @@ -35,9 +40,19 @@ fn get_file_content(path: &str) -> String { return String::from_utf8(buffer).unwrap(); } -fn get_post_title() -> Vec<String> { +fn get_post_entry(path: &String) -> PostEntry { + let sub_title = str::replace(path, "_", " "); + let title = str::replace(sub_title.as_str(), ".html", ""); + PostEntry { + title: String::from(title), + file: String::from(path), + } +} + +fn get_post_title() -> Vec<PostEntry> { PostAsset::iter() .map(|e| format!("{}", e)) + .map(|e| get_post_entry(&e)) .collect() } |