404 page
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-10-15 20:57:35 +02:00
parent 3b9d6acb72
commit fabc0103be
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 42 additions and 6 deletions

View file

@ -1,28 +1,39 @@
use actix_web::{web, HttpResponse, Responder}; use actix_web::{web, HttpRequest, HttpResponse, Responder};
use cached::proc_macro::once; use cached::proc_macro::once;
use ramhorns::Content; use ramhorns::Content;
use crate::{ use crate::{
config::Config, config::Config,
misc::utils::get_url,
template::{Infos, NavBar}, template::{Infos, NavBar},
}; };
pub async fn page(config: web::Data<Config>) -> impl Responder { pub async fn page(req: HttpRequest, config: web::Data<Config>) -> impl Responder {
HttpResponse::NotFound().body(build_page(config.get_ref().to_owned())) HttpResponse::NotFound().body(build_page(
config.get_ref().to_owned(),
get_url(req.connection_info()),
))
} }
#[derive(Content, Debug)] #[derive(Content, Debug)]
struct NotFoundTemplate { struct NotFoundTemplate {
navbar: NavBar, navbar: NavBar,
www: String,
onion: Option<String>,
} }
#[once(time = 60)] #[once(time = 60)]
fn build_page(config: Config) -> String { fn build_page(config: Config, url: String) -> String {
config.tmpl.render( config.tmpl.render(
"404.html", "404.html",
NotFoundTemplate { NotFoundTemplate {
navbar: NavBar::default(), navbar: NavBar::default(),
www: url,
onion: config.fc.onion,
},
Infos {
page_desc: Some("Une page perdu du web".into()),
..Infos::default()
}, },
Infos::default(),
) )
} }

View file

@ -6,7 +6,32 @@
<body> <body>
<header>{{>navbar.html}}</header> <header>{{>navbar.html}}</header>
<main> <main>
<p style="color: aliceblue">404 :/</p> {{#data}}
<h1>Perdu ?</h1>
<p>Vous pouvez revenir sur le site via :</p>
<ul>
<li><p>La barre de navigation</p></li>
<li>
<p>
Le <a href="{{www}} ">site internet</a> (disponible grâce au projet
<a href="http://info.cern.ch/hypertext/WWW/TheProject.html">W3</a>).
</p>
</li>
{{#onion}}
<li>
<p>
Le <a href="{{onion}} ">site onion</a> (disponible grâce au réseau
<a href="https://www.torproject.org/">Tor</a>).
</p>
</li>
{{/onion}}
</ul>
{{/data}}
</main> </main>
</body> </body>
</html> </html>