diff --git a/src/site.rs b/src/site.rs index 9d4ec70..a38d2e9 100644 --- a/src/site.rs +++ b/src/site.rs @@ -13,11 +13,19 @@ lazy_static! { #[derive(BartDisplay)] #[template = "templates/layout.html"] -pub struct Layout<'a, T: 'a + fmt::Display> { +struct Layout<'a, T: 'a + fmt::Display> { pub title: &'a str, pub body: &'a T, } +#[derive(BartDisplay)] +#[template = "templates/404.html"] +struct NotFound; + +#[derive(BartDisplay)] +#[template = "templates/500.html"] +struct InternalServerError; + pub struct Site { state: State } @@ -43,7 +51,10 @@ impl Service for Site { futures::finished( Response::new() .with_header(ContentType(TEXT_HTML.clone())) - .with_body(format!("Page not found")) + .with_body(Layout { + title: "Not found", + body: &NotFound, + }.to_string()) .with_status(hyper::StatusCode::NotFound) ).boxed() } else { @@ -64,7 +75,10 @@ impl Service for Site { futures::finished( Response::new() .with_header(ContentType(TEXT_HTML.clone())) - .with_body(format!("Article not found.")) + .with_body(Layout { + title: "Not found", + body: &NotFound, + }.to_string()) .with_status(hyper::StatusCode::NotFound) ).boxed() }, @@ -73,7 +87,10 @@ impl Service for Site { futures::finished( Response::new() .with_header(ContentType(TEXT_HTML.clone())) - .with_body(format!("Internal server error")) + .with_body(Layout { + title: "Internal server error", + body: &InternalServerError, + }.to_string()) .with_status(hyper::StatusCode::InternalServerError) ).boxed() } diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 0000000..a084c6c --- /dev/null +++ b/templates/404.html @@ -0,0 +1 @@ +
Not found
diff --git a/templates/500.html b/templates/500.html new file mode 100644 index 0000000..af120c4 --- /dev/null +++ b/templates/500.html @@ -0,0 +1 @@ +Internal server error