diff --git a/Cargo.toml b/Cargo.toml index 34b7d28..bddce78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ lazy_static = "1.1" serde = "1.0" serde_derive = "1.0" tera = "*" +pulldown-cmark = { version = "0.1.2", default-features = false } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e143926..87d8d47 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,8 @@ extern crate rocket_contrib; #[macro_use] extern crate serde_derive; +extern crate pulldown_cmark; + mod pg_pool; mod schema; mod models; @@ -30,13 +32,15 @@ use tera::Context; use rocket_contrib::Template; use rocket::response::Redirect; +use pulldown_cmark::{html, Parser}; + #[get("/")] fn index(conn: DbConn) -> Template { let mut context = Context::new(); let result = posts.filter(published.eq(true)).load::(&*conn).expect("cannot load posts"); - context.add("posts", &result); + context.insert("posts", &result); println!("{:?}", result); @@ -47,9 +51,15 @@ fn index(conn: DbConn) -> Template { fn single_archives(conn: DbConn, archives_id: i32) -> Template { let mut context = Context::new(); - let result = posts.find(archives_id).first::(&*conn).expect(""); + let result: Post = posts.find(archives_id).first::(&*conn).expect(""); - context.add("post", &result); + let parser = Parser::new(&result.body); + + let mut content_buf = String::new(); + html::push_html(&mut content_buf, parser); + + context.insert("post", &result); + context.insert("content", &content_buf); Template::render("archives", &context) } diff --git a/static/archives.tera b/static/archives.tera index 774cb11..5a7fb8d 100644 --- a/static/archives.tera +++ b/static/archives.tera @@ -1,4 +1,6 @@

{{ post.title }}

-

{{ post.body }}

+
+ {{ content }} +
\ No newline at end of file