From 2bc0f144751705ceac490a9a90262c34fe5ba356 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 19 Apr 2023 20:54:05 +0200 Subject: [PATCH] blog works! sort of --- src/routes/blog.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/routes/blog.rs b/src/routes/blog.rs index 0c233e6..525784d 100644 --- a/src/routes/blog.rs +++ b/src/routes/blog.rs @@ -1,5 +1,6 @@ use actix_web::{get, web, HttpResponse, Responder}; use cached::proc_macro::once; +use glob::glob; use ramhorns::Content; use crate::{ @@ -17,18 +18,36 @@ struct BlogIndexTemplate { posts: Option>, } -#[derive(Content)] +#[derive(Content, Debug)] struct Post { title: String, url: String, - file: File, } #[once(time = 60)] pub fn get_index(config: Config) -> String { + let paths = glob("data/blog/*.md") + .unwrap() + .map(|f| { + let filename = f + .unwrap() + .file_name() + .unwrap() + .to_string_lossy() + .to_string(); + let file_without_ext = filename.split_at(filename.len() - 3).0; + Post { + title: file_without_ext.to_string(), + url: file_without_ext.to_string(), + } + }) + .collect::>(); + config.tmpl.render( "blog/index.html", - BlogIndexTemplate { posts: None }, + BlogIndexTemplate { + posts: if paths.is_empty() { None } else { Some(paths) }, + }, Infos { page_title: Some("Blog".to_string()), page_desc: Some("Liste des posts d'Anri".to_string()),