2023-04-29 14:09:41 +02:00
|
|
|
use actix_web::{get, web, HttpRequest, HttpResponse, Responder};
|
2023-04-11 10:45:25 +02:00
|
|
|
use cached::proc_macro::once;
|
2023-02-08 20:49:05 +01:00
|
|
|
|
2023-04-29 14:09:41 +02:00
|
|
|
use crate::{config::Config, misc::utils::get_url, template::Infos};
|
2023-02-09 11:19:53 +01:00
|
|
|
|
2023-02-08 20:49:05 +01:00
|
|
|
#[get("/")]
|
2023-04-29 14:09:41 +02:00
|
|
|
pub async fn page(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
|
|
|
|
HttpResponse::Ok().body(build_page(
|
|
|
|
config.get_ref().to_owned(),
|
|
|
|
get_url(req.connection_info()),
|
|
|
|
))
|
2023-02-08 20:49:05 +01:00
|
|
|
}
|
2023-02-08 22:14:57 +01:00
|
|
|
|
2023-04-11 10:45:25 +02:00
|
|
|
#[once(time = 60)]
|
2023-04-29 14:09:41 +02:00
|
|
|
pub fn build_page(config: Config, url: String) -> String {
|
2023-04-11 10:16:46 +02:00
|
|
|
config.tmpl.render(
|
|
|
|
"index.html",
|
2023-04-21 19:47:41 +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()),
|
2023-04-19 20:07:53 +02:00
|
|
|
page_kw: None,
|
2023-04-29 14:09:41 +02:00
|
|
|
url,
|
2023-04-11 10:16:46 +02:00
|
|
|
},
|
|
|
|
)
|
2023-02-08 22:14:57 +01:00
|
|
|
}
|