blog works! sort of
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-04-19 20:54:05 +02:00
parent 6f5b563f97
commit 2bc0f14475
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -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<Vec<Post>>,
}
#[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::<Vec<Post>>();
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()),