From 16ef06ffb363b6304d0d5269b30dedbdd07288df Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sat, 14 May 2022 00:00:22 +0200 Subject: feat: Add title parser Add title parse so it yields a better post list. --- src/main.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src') 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, + posts: Vec, } #[derive(TemplateOnce)] @@ -35,9 +40,19 @@ fn get_file_content(path: &str) -> String { return String::from_utf8(buffer).unwrap(); } -fn get_post_title() -> Vec { +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 { PostAsset::iter() .map(|e| format!("{}", e)) + .map(|e| get_post_entry(&e)) .collect() } -- cgit v1.2.3