use actix_web::{get, web, HttpResponse, Responder}; use cached::proc_macro::once; use ramhorns::Content; use crate::{ config::Config, template::{read_md_file, File, Infos}, }; #[get("/blog")] pub async fn index(config: web::Data) -> impl Responder { HttpResponse::Ok().body(get_index(config.get_ref().clone())) } #[derive(Content)] struct BlogIndexTemplate { post: Option, } #[once(time = 60)] pub fn get_index(_config: Config) -> String { String::from("Salut pour tous") } #[get("/blog/{id}")] pub async fn page(path: web::Path<(String,)>, config: web::Data) -> impl Responder { HttpResponse::Ok().body(get_page(path.into_inner().0, config.get_ref().clone())) } pub fn get_page(file: String, config: Config) -> String { let blog_dir = "data/blog"; let ext = ".md"; let post = read_md_file(&format!("{blog_dir}/{file}{ext}")); let infos = Infos { page_title: Some(format!("Post: {file}")), page_desc: Some("Blog d'Anri".to_string()), }; config .tmpl .render("blog/post.html", BlogIndexTemplate { post }, infos) }