2023-10-24 13:27:02 +02:00
|
|
|
use actix_web::{get, web, Responder};
|
2023-04-11 10:45:25 +02:00
|
|
|
use cached::proc_macro::once;
|
2023-10-15 20:58:20 +02:00
|
|
|
use ramhorns::Content;
|
2023-02-08 20:49:05 +01:00
|
|
|
|
2023-10-15 20:58:20 +02:00
|
|
|
use crate::{
|
|
|
|
config::Config,
|
2024-01-24 12:38:37 +01:00
|
|
|
misc::{
|
|
|
|
markdown::{read_file, File, TypeFileMetadata},
|
|
|
|
utils::{make_kw, Html},
|
|
|
|
},
|
2023-10-15 20:58:20 +02:00
|
|
|
template::{Infos, NavBar},
|
|
|
|
};
|
2023-02-09 11:19:53 +01:00
|
|
|
|
2023-02-08 20:49:05 +01:00
|
|
|
#[get("/")]
|
2023-10-24 11:50:30 +02:00
|
|
|
async fn page(config: web::Data<Config>) -> impl Responder {
|
2023-10-24 13:27:02 +02:00
|
|
|
Html(build_page(config.get_ref().to_owned()))
|
2023-02-08 20:49:05 +01:00
|
|
|
}
|
2023-02-08 22:14:57 +01:00
|
|
|
|
2023-10-15 20:58:20 +02:00
|
|
|
#[derive(Content, Debug)]
|
|
|
|
struct IndexTemplate {
|
|
|
|
navbar: NavBar,
|
|
|
|
fullname: String,
|
2024-01-24 12:38:37 +01:00
|
|
|
content: Option<File>,
|
2023-10-15 20:58:20 +02:00
|
|
|
}
|
|
|
|
|
2023-04-11 10:45:25 +02:00
|
|
|
#[once(time = 60)]
|
2023-10-24 11:50:30 +02:00
|
|
|
fn build_page(config: Config) -> String {
|
2024-01-24 12:38:37 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-04-11 10:16:46 +02:00
|
|
|
config.tmpl.render(
|
|
|
|
"index.html",
|
2023-10-15 20:58:20 +02:00
|
|
|
IndexTemplate {
|
|
|
|
navbar: NavBar {
|
|
|
|
index: true,
|
|
|
|
..NavBar::default()
|
|
|
|
},
|
|
|
|
fullname: config
|
|
|
|
.fc
|
|
|
|
.fullname
|
|
|
|
.to_owned()
|
|
|
|
.unwrap_or("Fullname".to_owned()),
|
2024-01-24 12:38:37 +01:00
|
|
|
content,
|
2023-10-15 20:58:20 +02:00
|
|
|
},
|
2023-04-11 10:16:46 +02:00
|
|
|
Infos {
|
2023-04-28 12:49:48 +02:00
|
|
|
page_title: config.fc.fullname,
|
2023-04-26 12:07:46 +02:00
|
|
|
page_desc: Some("Page principale".into()),
|
2024-01-24 12:38:37 +01:00
|
|
|
page_kw: make_kw(&["index", "étudiant", "accueil"]),
|
2023-04-11 10:16:46 +02:00
|
|
|
},
|
|
|
|
)
|
2023-02-08 22:14:57 +01:00
|
|
|
}
|