Merge pull request #158 from Ilphrin/master

Show the total number of article on a blog
This commit is contained in:
Baptiste Gelez 2018-07-21 22:32:45 +02:00 committed by GitHub
commit 24f2030881
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 2 deletions

View File

@ -91,6 +91,12 @@ impl Post {
.expect("Error loading recent posts for blog")
}
pub fn get_for_blog(conn: &PgConnection, blog:&Blog) -> Vec<Post> {
posts::table.filter(posts::blog_id.eq(blog.id))
.load::<Post>(conn)
.expect("Error loading posts for blog")
}
pub fn get_authors(&self, conn: &PgConnection) -> Vec<User> {
use schema::users;
use schema::post_authors;

View File

@ -325,3 +325,8 @@ msgstr ""
msgid "Optional"
msgstr ""
msgid "One article in this blog"
msgid_plural "{{ count }} articles in this blog"
msgstr[0] ""
msgstr[1] ""

View File

@ -23,6 +23,7 @@ use plume_models::{
fn details(name: String, conn: DbConn, user: Option<User>) -> Template {
may_fail!(user, Blog::find_by_fqn(&*conn, name), "Requested blog couldn't be found", |blog| {
let recents = Post::get_recents_for_blog(&*conn, &blog, 5);
let articles = Post::get_for_blog(&*conn, &blog);
let authors = &blog.list_authors(&*conn);
Template::render("blogs/details", json!({
@ -31,7 +32,8 @@ fn details(name: String, conn: DbConn, user: Option<User>) -> Template {
"is_author": user.map(|x| x.is_author_in(&*conn, blog.clone())),
"recents": recents.into_iter().map(|p| p.to_json(&*conn)).collect::<Vec<serde_json::Value>>(),
"authors": authors.into_iter().map(|u| u.to_json(&*conn)).collect::<Vec<serde_json::Value>>(),
"n_authors": authors.len()
"n_authors": authors.len(),
"n_articles": articles.len()
}))
})
}

View File

@ -19,7 +19,10 @@
<a class="author" href="/@/{{ author.fqn }}">{{ name }}</a>{% if not loop.last %},{% endif %}
{% endfor %}
</p>
<p>
{{ "{{ count }} articles in this blog" | _n(singular="One article in this blog", count = n_articles) }}
</p>
<section>
<h2>{{ "Latest articles" | _ }}</h2>
{% if recents | length < 1 %}