fixed the way to display correctly the posts

pull/1/head
kirbylife 2019-11-18 02:14:29 -06:00
parent 21d9d25215
commit cbc88b34b8
2 changed files with 7 additions and 3 deletions

View File

@ -7,6 +7,7 @@ pub mod schema;
extern crate rocket; extern crate rocket;
#[macro_use] #[macro_use]
extern crate diesel; extern crate diesel;
extern crate comrak;
extern crate dotenv; extern crate dotenv;
extern crate rand; extern crate rand;
extern crate rocket_contrib; extern crate rocket_contrib;
@ -14,6 +15,7 @@ extern crate tera;
use self::diesel::prelude::*; use self::diesel::prelude::*;
use self::models::*; use self::models::*;
use comrak::{markdown_to_html, ComrakOptions};
use diesel::pg::PgConnection; use diesel::pg::PgConnection;
use dotenv::dotenv; use dotenv::dotenv;
use rand::Rng; 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_fmt = TITLES[rng.gen_range(0, TITLES.len())];
let title = str::replace(title_fmt, "{}", "CódigoComentado"); 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("title", &title);
context.insert("post", &post); context.insert("post", &post);

View File

@ -1,11 +1,11 @@
{% extends "base" %} {% extends "base" %}
{% block title %}{% endblock title %} {% block title %}CódigoComentado - {{post.title}}{% endblock title %}
{% block content %} {% block content %}
<h1><strong>Title: </strong>{{ post.title }}</h1> <h1><strong>Title: </strong>{{ post.title }}</h1>
<strong>Content:</strong> <strong>Content:</strong>
<article> <article>
{{ post.content | split(pat="\n") | join(sep="----------") }} {{ post.content | safe }}
</article> </article>
{% endblock content %} {% endblock content %}