mylloon.fr/src/routes/not_found.rs

40 lines
923 B
Rust
Raw Normal View History

use actix_web::{web, HttpRequest, HttpResponse, Responder};
2023-04-11 10:45:25 +02:00
use cached::proc_macro::once;
use ramhorns::Content;
2023-02-08 22:27:40 +01:00
use crate::{
config::Config,
misc::utils::get_url,
template::{Infos, NavBar},
};
2023-02-09 11:19:53 +01:00
pub async fn page(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
HttpResponse::NotFound().body(build_page(
config.get_ref().to_owned(),
get_url(req.connection_info()),
))
}
#[derive(Content, Debug)]
struct NotFoundTemplate {
navbar: NavBar,
www: String,
onion: Option<String>,
2023-02-09 10:55:49 +01:00
}
2023-04-11 10:45:25 +02:00
#[once(time = 60)]
fn build_page(config: Config, url: String) -> String {
config.tmpl.render(
"404.html",
NotFoundTemplate {
navbar: NavBar::default(),
www: url,
onion: config.fc.onion,
},
Infos {
page_desc: Some("Une page perdu du web".into()),
..Infos::default()
},
)
2023-02-08 22:27:40 +01:00
}