use actix_web::{get, web, Responder}; use cached::proc_macro::once; use ramhorns::Content; use crate::{ config::Config, misc::{ markdown::{read_file, File, TypeFileMetadata}, utils::{make_kw, Html}, }, template::{Infos, NavBar}, }; #[get("/")] async fn page(config: web::Data) -> impl Responder { Html(build_page(config.get_ref().to_owned())) } #[derive(Content, Debug)] struct IndexTemplate { navbar: NavBar, fullname: String, content: Option, } #[once(time = 60)] fn build_page(config: Config) -> String { let mut content = read_file( &format!("{}/index.md", config.locations.data_dir), TypeFileMetadata::Generic, ); if content.is_none() { content = read_file("README.md", TypeFileMetadata::Generic); } config.tmpl.render( "index.html", IndexTemplate { navbar: NavBar { index: true, ..NavBar::default() }, fullname: config .fc .fullname .to_owned() .unwrap_or("Fullname".to_owned()), content, }, Infos { page_title: config.fc.fullname, page_desc: Some("Page principale".into()), page_kw: make_kw(&["index", "étudiant", "accueil"]), }, ) }