Add visitor counter
parent
b016fc5bab
commit
bbba1ead64
|
@ -79,4 +79,14 @@ pub mod posts {
|
||||||
))
|
))
|
||||||
.get_result(&connection)
|
.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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,8 @@ fn show_post(title: String) -> Template {
|
||||||
|
|
||||||
match posts::get_post(id) {
|
match posts::get_post(id) {
|
||||||
Ok(mut post) => {
|
Ok(mut post) => {
|
||||||
|
posts::add_visit(id);
|
||||||
|
|
||||||
let mut comrak_options = Options::default();
|
let mut comrak_options = Options::default();
|
||||||
comrak_options.extension.table = true;
|
comrak_options.extension.table = true;
|
||||||
comrak_options.extension.autolink = true;
|
comrak_options.extension.autolink = true;
|
||||||
|
|
|
@ -43,13 +43,13 @@
|
||||||
{% if loop.index is odd %}
|
{% if loop.index is odd %}
|
||||||
<p class="colored">{{ post.id }}</p>
|
<p class="colored">{{ post.id }}</p>
|
||||||
<p class="colored"><a href="/post/{{ post.title | slugify }}-{{ post.id }}">{{ post.title }}</a></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 center">{{ post.published }}</p>
|
||||||
<p class="colored"><a href="/admin/edit_post/{{ post.id }}">Editar</a></p>
|
<p class="colored"><a href="/admin/edit_post/{{ post.id }}">Editar</a></p>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>{{ post.id }}</p>
|
<p>{{ post.id }}</p>
|
||||||
<p><a href="/post/{{ post.title | slugify }}-{{ post.id }}">{{ post.title }}</a></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 class="center">{{ post.published }}</p>
|
||||||
<p><a href="/admin/edit_post/{{ post.id }}">Editar</a></p>
|
<p><a href="/admin/edit_post/{{ post.id }}">Editar</a></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in New Issue