mylloon.fr/src/routes/blog.rs

35 lines
927 B
Rust
Raw Normal View History

2023-04-14 11:30:58 +02:00
use actix_web::{get, web, HttpResponse, Responder};
use cached::proc_macro::once;
use ramhorns::Content;
2023-04-19 20:08:15 +02:00
use crate::{config::Config, misc::utils::get_post, template::File};
2023-04-14 11:30:58 +02:00
#[get("/blog")]
pub async fn index(config: web::Data<Config>) -> impl Responder {
HttpResponse::Ok().body(get_index(config.get_ref().clone()))
}
#[derive(Content)]
2023-04-19 18:55:03 +02:00
struct BlogIndexTemplate {
post: Option<File>,
}
2023-04-14 11:30:58 +02:00
#[once(time = 60)]
pub fn get_index(_config: Config) -> String {
String::from("Salut pour tous")
}
#[get("/blog/{id}")]
2023-04-19 18:55:03 +02:00
pub async fn page(path: web::Path<(String,)>, config: web::Data<Config>) -> impl Responder {
2023-04-14 11:30:58 +02:00
HttpResponse::Ok().body(get_page(path.into_inner().0, config.get_ref().clone()))
}
2023-04-19 18:55:03 +02:00
pub fn get_page(file: String, config: Config) -> String {
2023-04-19 20:08:15 +02:00
let mut post = None;
let infos = get_post(&mut post, file);
2023-04-19 18:55:03 +02:00
config
.tmpl
.render("blog/post.html", BlogIndexTemplate { post }, infos)
2023-04-14 11:30:58 +02:00
}