From cd24b0f057c065e468ae4fc7ff910d07f2c0e447 Mon Sep 17 00:00:00 2001 From: "Kevin \"Ilphrin\" Pellet" Date: Sat, 21 Jul 2018 16:58:30 +0200 Subject: [PATCH 1/2] Show the total number of article on a blog fixes #150 --- plume-models/src/posts.rs | 6 ++++++ src/routes/blogs.rs | 4 +++- templates/blogs/details.html.tera | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 856ec349..5a04b9f8 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -91,6 +91,12 @@ impl Post { .expect("Error loading recent posts for blog") } + pub fn get_for_blog(conn: &PgConnection, blog:&Blog) -> Vec { + posts::table.filter(posts::blog_id.eq(blog.id)) + .load::(conn) + .expect("Error loading posts for blog") + } + pub fn get_authors(&self, conn: &PgConnection) -> Vec { use schema::users; use schema::post_authors; diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index 1a42f405..6ce0a874 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -23,6 +23,7 @@ use plume_models::{ fn details(name: String, conn: DbConn, user: Option) -> 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) -> Template { "is_author": user.map(|x| x.is_author_in(&*conn, blog.clone())), "recents": recents.into_iter().map(|p| p.to_json(&*conn)).collect::>(), "authors": authors.into_iter().map(|u| u.to_json(&*conn)).collect::>(), - "n_authors": authors.len() + "n_authors": authors.len(), + "n_articles": articles.len() })) }) } diff --git a/templates/blogs/details.html.tera b/templates/blogs/details.html.tera index 96d805c1..37799663 100644 --- a/templates/blogs/details.html.tera +++ b/templates/blogs/details.html.tera @@ -19,7 +19,10 @@ {{ name }}{% if not loop.last %},{% endif %} {% endfor %}

- +

+ {{ "{{ count }} articles in this blog" | _n(singular="One article in this blog", count = n_articles) }} +

+

{{ "Latest articles" | _ }}

{% if recents | length < 1 %} From 4b84fb7ed0fb1d151a04769031a5d096b8ba03af Mon Sep 17 00:00:00 2001 From: "Kevin \"Ilphrin\" Pellet" Date: Sat, 21 Jul 2018 20:59:47 +0200 Subject: [PATCH 2/2] Add translation string for article count on blog --- po/plume.pot | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/po/plume.pot b/po/plume.pot index 0fdd5303..c61456af 100644 --- a/po/plume.pot +++ b/po/plume.pot @@ -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] ""