This commit is contained in:
parent
6f5b563f97
commit
2bc0f14475
1 changed files with 22 additions and 3 deletions
|
@ -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()),
|
||||
|
|
Loading…
Reference in a new issue