Compare commits

..

No commits in common. "bbba1ead645100e05c0a0617250c2536fd59d1cf" and "f793227b82f84ec0938fdd7463767157e121dab7" have entirely different histories.

5 changed files with 30 additions and 37 deletions

View File

@ -1,16 +1,16 @@
[package]
name = "codigocomentado"
version = "0.1.0"
authors = ["kirbylife <kirbylife@protonmail.com>"]
authors = ["kirbylife <gabriel13m@gmail.com>"]
edition = "2021"
[dependencies]
rocket = { version = "0.5.0", features = ["secrets"] }
rocket_dyn_templates = { version = "0.1.0", features = ["tera"] }
diesel = { version = "1.0.0", features = ["postgres", "chrono"] }
dotenv = "0.15.0"
rand = "0.8.5"
dotenv = "0.9.0"
rand = "0.6.0"
chrono = { version = "0.4.9", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
comrak = "0.24.1"
tera = "1.19.1"
comrak = "0.6"
tera = "1.19.1"

View File

@ -79,14 +79,4 @@ pub mod posts {
))
.get_result(&connection)
}
pub fn add_visit(post_id: i32) {
use crate::schema::posts::dsl::*;
let connection = establish_connection();
diesel::update(posts.filter(id.eq(post_id)))
.set(views.eq(views + 1))
.execute(&connection)
.unwrap();
}
}

View File

@ -10,7 +10,7 @@ extern crate rocket;
#[macro_use]
extern crate diesel;
use comrak::{markdown_to_html, Options};
use comrak::{markdown_to_html, ComrakOptions};
use controllers::posts;
use dotenv::dotenv;
use rocket::fs::{FileServer, NamedFile};
@ -35,11 +35,13 @@ fn index(page: Option<u64>) -> Template {
fn rss_feed() -> RawXml<Template> {
let (mut posts, _) = posts::get_posts(None);
let mut comrak_options = Options::default();
comrak_options.extension.table = true;
comrak_options.extension.autolink = true;
comrak_options.extension.tasklist = true;
comrak_options.render.unsafe_ = true;
let comrak_options = ComrakOptions {
ext_table: true,
ext_autolink: true,
ext_tasklist: true,
unsafe_: true,
..ComrakOptions::default()
};
posts.iter_mut().for_each(|post| {
let content = markdown_to_html(&post.content, &comrak_options);
@ -55,11 +57,13 @@ fn rss_feed() -> RawXml<Template> {
fn atom_feed() -> RawXml<Template> {
let (mut posts, _) = posts::get_posts(None);
let mut comrak_options = Options::default();
comrak_options.extension.table = true;
comrak_options.extension.autolink = true;
comrak_options.extension.tasklist = true;
comrak_options.render.unsafe_ = true;
let comrak_options = ComrakOptions {
ext_table: true,
ext_autolink: true,
ext_tasklist: true,
unsafe_: true,
..ComrakOptions::default()
};
posts.iter_mut().for_each(|post| {
let content = markdown_to_html(&post.content, &comrak_options);
@ -78,14 +82,13 @@ fn show_post(title: String) -> Template {
match posts::get_post(id) {
Ok(mut post) => {
posts::add_visit(id);
let mut comrak_options = Options::default();
comrak_options.extension.table = true;
comrak_options.extension.autolink = true;
comrak_options.extension.tasklist = true;
comrak_options.render.unsafe_ = true;
comrak_options.extension.header_ids = Some("id-".to_string());
let comrak_options = ComrakOptions {
ext_table: true,
ext_autolink: true,
ext_tasklist: true,
unsafe_: true,
..ComrakOptions::default()
};
let content = markdown_to_html(&post.content, &comrak_options);
post.content = content;

View File

@ -16,7 +16,7 @@ const TITLES: [&str; 11] = [
pub fn gen_title() -> String {
let mut rng = rand::thread_rng();
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");
title.to_string()
}

View File

@ -43,13 +43,13 @@
{% if loop.index is odd %}
<p class="colored">{{ post.id }}</p>
<p class="colored"><a href="/post/{{ post.title | slugify }}-{{ post.id }}">{{ post.title }}</a></p>
<p class="colored center">{{ post.views }}</p>
<p class="colored center">0</p>
<p class="colored center">{{ post.published }}</p>
<p class="colored"><a href="/admin/edit_post/{{ post.id }}">Editar</a></p>
{% else %}
<p>{{ post.id }}</p>
<p><a href="/post/{{ post.title | slugify }}-{{ post.id }}">{{ post.title }}</a></p>
<p class="center">{{ post.views }}</p>
<p class="center">0</p>
<p class="center">{{ post.published }}</p>
<p><a href="/admin/edit_post/{{ post.id }}">Editar</a></p>
{% endif %}