diff --git a/src/site.rs b/src/site.rs index d832799..9d4ec70 100644 --- a/src/site.rs +++ b/src/site.rs @@ -1,3 +1,5 @@ +use std::fmt; + use futures::{self, Future}; use hyper; use hyper::header::ContentType; @@ -9,6 +11,13 @@ lazy_static! { static ref TEXT_HTML: mime::Mime = "text/html;charset=utf-8".parse().unwrap(); } +#[derive(BartDisplay)] +#[template = "templates/layout.html"] +pub struct Layout<'a, T: 'a + fmt::Display> { + pub title: &'a str, + pub body: &'a T, +} + pub struct Site { state: State } @@ -44,7 +53,10 @@ impl Service for Site { futures::finished( Response::new() .with_header(ContentType(TEXT_HTML.clone())) - .with_body(format!("{}", article)) + .with_body(Layout { + title: &article.title, + body: &article + }.to_string()) .with_status(hyper::StatusCode::Ok) ).boxed() }, diff --git a/templates/article.html b/templates/article.html index c675879..f2d8477 100644 --- a/templates/article.html +++ b/templates/article.html @@ -1,13 +1,5 @@ - - - -{{title}} - -

{{id}}-{{revision}}

{{created}}

{{title}}

{{body}}

- - diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 0000000..9000d21 --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,9 @@ + + + +{{title}} + + +{{{body}}} + +