added 404 custom page
parent
a56dfcb749
commit
ac70178423
17
src/main.rs
17
src/main.rs
|
@ -19,6 +19,7 @@ use comrak::{markdown_to_html, ComrakOptions};
|
|||
use diesel::pg::PgConnection;
|
||||
use dotenv::dotenv;
|
||||
use rand::Rng;
|
||||
use rocket::Request;
|
||||
use rocket_contrib::serve::StaticFiles;
|
||||
use rocket_contrib::templates::Template;
|
||||
use std::env;
|
||||
|
@ -115,10 +116,26 @@ fn show_post(title: String) -> Template {
|
|||
Template::render("post", context)
|
||||
}
|
||||
|
||||
#[catch(404)]
|
||||
fn not_found_404(req: &Request) -> Template {
|
||||
let mut context = Context::new();
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let title_fmt = TITLES[rng.gen_range(0, TITLES.len())];
|
||||
let title = str::replace(title_fmt, "{}", "CódigoComentado");
|
||||
|
||||
let uri = format!("{}", req.uri());
|
||||
|
||||
context.insert("title", &title);
|
||||
context.insert("url", &uri);
|
||||
Template::render("404", context)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
rocket::ignite()
|
||||
.attach(Template::fairing())
|
||||
.mount("/", routes![index, show_post])
|
||||
.mount("/static", StaticFiles::from("static"))
|
||||
.register(catchers![not_found_404])
|
||||
.launch();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
.container {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto 1fr;
|
||||
grid-template-rows: 1fr 2fr;
|
||||
grid-template-areas:
|
||||
". title ."
|
||||
". info .";
|
||||
}
|
||||
|
||||
.container h1 {
|
||||
grid-area: title;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.container span {
|
||||
grid-area: info;
|
||||
font-family: monospace;
|
||||
font-size: 20px;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
{% extends "base" %}
|
||||
|
||||
{% block extracss %}
|
||||
<link href="/static/css/404.css" rel="stylesheet"/>
|
||||
{% endblock extracss %}
|
||||
|
||||
{% block content %}
|
||||
<h1>404</h1>
|
||||
<span>
|
||||
=> Error: No matching routes for GET {{ url }} <br/>
|
||||
=> Warning: Responding with 404 Not Found catcher.
|
||||
</span>
|
||||
{% endblock content %}
|
Loading…
Reference in New Issue