diff --git a/src/main.rs b/src/main.rs index 7309afa..fb3ef6e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ extern crate chrono; extern crate clap; extern crate futures; extern crate hyper; +extern crate pulldown_cmark; use std::net::SocketAddr; diff --git a/src/models.rs b/src/models.rs index ad0cd4c..c3c0038 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,7 +1,6 @@ use chrono; -#[derive(BartDisplay, Clone, Debug, Queryable)] -#[template="templates/article_revision.html"] +#[derive(Debug, Queryable)] pub struct ArticleRevision { pub article_id: i32, pub revision: i32, diff --git a/src/site.rs b/src/site.rs index 401e84d..e26610b 100644 --- a/src/site.rs +++ b/src/site.rs @@ -10,6 +10,15 @@ use models; use state::State; use web::{Lookup, Resource}; +fn render_markdown(src: &str) -> String { + use pulldown_cmark::{Parser, html}; + + let p = Parser::new(src); + let mut buf = String::new(); + html::push_html(&mut buf, p); + buf +} + lazy_static! { static ref TEXT_HTML: mime::Mime = "text/html;charset=utf-8".parse().unwrap(); } @@ -87,11 +96,30 @@ impl Resource for ArticleResource { } fn get(self) -> futures::BoxFuture> { + use chrono::{self, TimeZone, Local}; + + #[derive(BartDisplay)] + #[template="templates/article_revision.html"] + struct Template<'a> { + article_id: i32, + revision: i32, + created: &'a chrono::DateTime, + + title: &'a str, + body: String, + } + self.head().map(move |head| head .with_body(Layout { title: &self.data.title, - body: &self.data + body: &Template { + article_id: self.data.article_id, + revision: self.data.revision, + created: &Local.from_utc_datetime(&self.data.created), + title: &self.data.title, + body: render_markdown(&self.data.body), + } }.to_string()) ).boxed() } diff --git a/templates/article_revision.html b/templates/article_revision.html index 9f6afe7..619388c 100644 --- a/templates/article_revision.html +++ b/templates/article_revision.html @@ -1,5 +1,20 @@ -

{{article_id}}-{{revision}}

-

{{created}}

- +

{{title}}

-

{{body}}

+
+ +
+{{{body}}} +
+ +
+
+
Article ID
+
{{article_id}}
+ +
Revision
+
{{revision}}
+ +
Last updated
+
{{created}}
+
+
diff --git a/templates/layout.html b/templates/layout.html index 9000d21..b40bcc8 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -2,6 +2,124 @@ {{title}} + + + {{{body}}}