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/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] "" 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 %}