From cbc88b34b892b52a60ff0b0077c5edee5ed4cc99 Mon Sep 17 00:00:00 2001 From: kirbylife Date: Mon, 18 Nov 2019 02:14:29 -0600 Subject: [PATCH] fixed the way to display correctly the posts --- src/main.rs | 6 +++++- templates/posts.html.tera | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index c23c714..7446fa7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ pub mod schema; extern crate rocket; #[macro_use] extern crate diesel; +extern crate comrak; extern crate dotenv; extern crate rand; extern crate rocket_contrib; @@ -14,6 +15,7 @@ extern crate tera; use self::diesel::prelude::*; use self::models::*; +use comrak::{markdown_to_html, ComrakOptions}; use diesel::pg::PgConnection; use dotenv::dotenv; use rand::Rng; @@ -94,7 +96,9 @@ fn show_post(title: String) -> Template { let title_fmt = TITLES[rng.gen_range(0, TITLES.len())]; let title = str::replace(title_fmt, "{}", "CódigoComentado"); - let post = get_post(id); + let mut post = get_post(id); + let content = markdown_to_html(&post.content, &ComrakOptions::default()); + post.content = content; context.insert("title", &title); context.insert("post", &post); diff --git a/templates/posts.html.tera b/templates/posts.html.tera index 0e1d742..c37baa1 100644 --- a/templates/posts.html.tera +++ b/templates/posts.html.tera @@ -1,11 +1,11 @@ {% extends "base" %} -{% block title %}{% endblock title %} +{% block title %}CódigoComentado - {{post.title}}{% endblock title %} {% block content %}

Title: {{ post.title }}

Content:
- {{ post.content | split(pat="\n") | join(sep="----------") }} + {{ post.content | safe }}
{% endblock content %}