use actix_web::{get, web, HttpRequest, HttpResponse, Responder}; use cached::proc_macro::once; use ramhorns::Content; use crate::{ config::Config, misc::utils::get_url, template::{Infos, NavBar}, }; #[get("/")] async fn page(req: HttpRequest, config: web::Data) -> impl Responder { HttpResponse::Ok().body(build_page( config.get_ref().to_owned(), get_url(req.connection_info()), )) } #[derive(Content, Debug)] struct IndexTemplate { navbar: NavBar, fullname: String, } #[once(time = 60)] fn build_page(config: Config, url: String) -> String { config.tmpl.render( "index.html", IndexTemplate { navbar: NavBar { index: true, ..NavBar::default() }, fullname: config .fc .fullname .to_owned() .unwrap_or("Fullname".to_owned()), }, Infos { page_title: config.fc.fullname, page_desc: Some("Page principale".into()), page_kw: None, url, }, ) }