use actix_web::{get, web, HttpResponse, Responder}; use cached::proc_macro::once; use ramhorns::Content; use crate::{config::Config, misc::utils::get_post, template::File}; #[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 mut post = None; let infos = get_post(&mut post, file); config .tmpl .render("blog/post.html", BlogIndexTemplate { post }, infos) }