Compare commits
3 Commits
f793227b82
...
bbba1ead64
Author | SHA1 | Date |
---|---|---|
kirbylife | bbba1ead64 | |
kirbylife | b016fc5bab | |
kirbylife | 64d09e0061 |
10
Cargo.toml
10
Cargo.toml
|
@ -1,16 +1,16 @@
|
|||
[package]
|
||||
name = "codigocomentado"
|
||||
version = "0.1.0"
|
||||
authors = ["kirbylife <gabriel13m@gmail.com>"]
|
||||
authors = ["kirbylife <kirbylife@protonmail.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.9.0"
|
||||
rand = "0.6.0"
|
||||
dotenv = "0.15.0"
|
||||
rand = "0.8.5"
|
||||
chrono = { version = "0.4.9", features = ["serde"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
comrak = "0.6"
|
||||
tera = "1.19.1"
|
||||
comrak = "0.24.1"
|
||||
tera = "1.19.1"
|
|
@ -79,4 +79,14 @@ 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();
|
||||
}
|
||||
}
|
||||
|
|
41
src/main.rs
41
src/main.rs
|
@ -10,7 +10,7 @@ extern crate rocket;
|
|||
#[macro_use]
|
||||
extern crate diesel;
|
||||
|
||||
use comrak::{markdown_to_html, ComrakOptions};
|
||||
use comrak::{markdown_to_html, Options};
|
||||
use controllers::posts;
|
||||
use dotenv::dotenv;
|
||||
use rocket::fs::{FileServer, NamedFile};
|
||||
|
@ -35,13 +35,11 @@ fn index(page: Option<u64>) -> Template {
|
|||
fn rss_feed() -> RawXml<Template> {
|
||||
let (mut posts, _) = posts::get_posts(None);
|
||||
|
||||
let comrak_options = ComrakOptions {
|
||||
ext_table: true,
|
||||
ext_autolink: true,
|
||||
ext_tasklist: true,
|
||||
unsafe_: true,
|
||||
..ComrakOptions::default()
|
||||
};
|
||||
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;
|
||||
|
||||
posts.iter_mut().for_each(|post| {
|
||||
let content = markdown_to_html(&post.content, &comrak_options);
|
||||
|
@ -57,13 +55,11 @@ fn rss_feed() -> RawXml<Template> {
|
|||
fn atom_feed() -> RawXml<Template> {
|
||||
let (mut posts, _) = posts::get_posts(None);
|
||||
|
||||
let comrak_options = ComrakOptions {
|
||||
ext_table: true,
|
||||
ext_autolink: true,
|
||||
ext_tasklist: true,
|
||||
unsafe_: true,
|
||||
..ComrakOptions::default()
|
||||
};
|
||||
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;
|
||||
|
||||
posts.iter_mut().for_each(|post| {
|
||||
let content = markdown_to_html(&post.content, &comrak_options);
|
||||
|
@ -82,13 +78,14 @@ fn show_post(title: String) -> Template {
|
|||
|
||||
match posts::get_post(id) {
|
||||
Ok(mut post) => {
|
||||
let comrak_options = ComrakOptions {
|
||||
ext_table: true,
|
||||
ext_autolink: true,
|
||||
ext_tasklist: true,
|
||||
unsafe_: true,
|
||||
..ComrakOptions::default()
|
||||
};
|
||||
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 content = markdown_to_html(&post.content, &comrak_options);
|
||||
post.content = content;
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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">0</p>
|
||||
<p class="colored center">{{ post.views }}</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">0</p>
|
||||
<p class="center">{{ post.views }}</p>
|
||||
<p class="center">{{ post.published }}</p>
|
||||
<p><a href="/admin/edit_post/{{ post.id }}">Editar</a></p>
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in New Issue