mirror of
https://github.com/deps-rs/deps.rs.git
synced 2024-11-22 10:26:30 +00:00
feat: add 404 page (#104)
* feat: add 404 page * feat: cache 404 results for 5 minutes
This commit is contained in:
parent
3f74371333
commit
a6b43e4e6d
2 changed files with 44 additions and 5 deletions
|
@ -362,10 +362,7 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn not_found() -> Response<Body> {
|
fn not_found() -> Response<Body> {
|
||||||
Response::builder()
|
views::html::error::render_404()
|
||||||
.status(StatusCode::NOT_FOUND)
|
|
||||||
.body(Body::empty())
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SELF_BASE_URL: Lazy<String> =
|
static SELF_BASE_URL: Lazy<String> =
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
use hyper::{Body, Response};
|
use hyper::{
|
||||||
|
header::{CACHE_CONTROL, CONTENT_TYPE},
|
||||||
|
Body, Response, StatusCode,
|
||||||
|
};
|
||||||
use maud::html;
|
use maud::html;
|
||||||
|
|
||||||
|
use crate::server::assets::STATIC_STYLE_CSS_PATH;
|
||||||
|
|
||||||
pub fn render(title: &str, descr: &str) -> Response<Body> {
|
pub fn render(title: &str, descr: &str) -> Response<Body> {
|
||||||
super::render_html(
|
super::render_html(
|
||||||
title,
|
title,
|
||||||
|
@ -20,3 +25,40 @@ pub fn render(title: &str, descr: &str) -> Response<Body> {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn render_404() -> Response<Body> {
|
||||||
|
let rendered = html! {
|
||||||
|
html {
|
||||||
|
head {
|
||||||
|
meta charset="utf-8";
|
||||||
|
meta name="viewport" content="width=device-width, initial-scale=1";
|
||||||
|
title { "404 - Deps.rs" }
|
||||||
|
link rel="icon" type="image/svg+xml" href="/static/logo.svg";
|
||||||
|
link rel="stylesheet" type="text/css" href=(STATIC_STYLE_CSS_PATH);
|
||||||
|
link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Fira+Sans:400,500,600";
|
||||||
|
link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Source+Code+Pro";
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
section class="hero is-light" {
|
||||||
|
div class="hero-head" { (super::render_navbar()) }
|
||||||
|
}
|
||||||
|
section class="section" {
|
||||||
|
div class="container" {
|
||||||
|
div class="notification is-info" {
|
||||||
|
p class="title is-3" { "Ooops, seems like you've hit a dead end!" }
|
||||||
|
p { "The page you were looking for could not be found. In other words, this is a " b { "404 error" } "." }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(super::render_footer(None))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Response::builder()
|
||||||
|
.status(StatusCode::NOT_FOUND)
|
||||||
|
.header(CONTENT_TYPE, "text/html; charset=utf-8")
|
||||||
|
.header(CACHE_CONTROL, "public, max-age=300, immutable")
|
||||||
|
.body(Body::from(rendered.0))
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue