Skip to content
Permalink
Browse files

Merge pull request #118 from wezm/category-counts

Include post count on yearly call for posts category page
  • Loading branch information...
wezm committed Nov 25, 2019
2 parents 785e0dd + f5394d3 commit 15cceb7e4be5807b486259baa9dd08850c452d0b
Showing with 31 additions and 17 deletions.
  1. +17 −17 content/_data/categories.json
  2. +1 −0 crystal/src/models/category.cr
  3. +13 −0 crystal/src/pages/categories/show_page.cr
@@ -1,19 +1,19 @@
[
{ "id": 0, "name": "All", "hashtag": "#all", "slug": "all", "description": "All posts." },
{ "id": 1, "name": "Community", "hashtag": "#community", "slug": "community", "description": "Initiatives in the Rust community." },
{ "id": 2, "name": "Computer Science", "hashtag": "#compsci", "slug": "computer-science", "description": "Covering data structures, algorithms, memory safety, etc." },
{ "id": 3, "name": "Crates", "hashtag": "#crates", "slug": "crates", "description": "Notable new or updated crates." },
{ "id": 4, "name": "DevOps and Deployment", "hashtag": "#devops", "slug": "devops-and-deployment", "description": "Building and deploying Rust, containerisation, continuous integration, etc." },
{ "id": 5, "name": "Embedded", "hashtag": "#embedded", "slug": "embedded", "description": "Rust on microcontrollers, IoT, devices." },
{ "id": 6, "name": "Games and Graphics", "hashtag": "#graphics", "slug": "games-and-graphics", "description": "Games built with Rust and other graphics related work." },
{ "id": 7, "name": "Getting Started", "hashtag": "#starting", "slug": "getting-started", "description": "Introductory posts, guides and tutorials for getting started with Rust." },
{ "id": 8, "name": "Language", "hashtag": "#language", "slug": "language", "description": "General posts about the Rust language." },
{ "id": 9, "name": "Operating Systems", "hashtag": "#os", "slug": "operating-systems", "description": "Using Rust to build or explore operating systems." },
{ "id": 10, "name": "Performance", "hashtag": "#performance", "slug": "performance", "description": "Optimisation, benchmarks, etc." },
{ "id": 11, "name": "Rust 2018", "hashtag": "#Rust2018", "slug": "rust-2018", "description": "Hopes and dreams for Rust in 2018." },
{ "id": 12, "name": "Rust 2019", "hashtag": "#rust2019", "slug": "rust-2019", "description": "Ideas from the community for Rust in 2019, and the next edition." },
{ "id": 16, "name": "Rust 2020", "hashtag": "#rust2020", "slug": "rust-2020", "description": "Ideas from the Rust community and picking a theme for 2020." },
{ "id": 13, "name": "Tools and Applications", "hashtag": "#tools", "slug": "tools-and-applications", "description": "Command line tools and GUI applications written in or for Rust." },
{ "id": 14, "name": "Security", "hashtag": "#security", "slug": "security", "description": "Security, cryptography, etc." },
{ "id": 15, "name": "Web and Network Services", "hashtag": "#web", "slug": "web-and-network-services", "description": "Web applications, web assembly, network daemons, etc." }
{ "id": 0, "name": "All", "hashtag": "#all", "slug": "all", "year": null, "description": "All posts." },
{ "id": 1, "name": "Community", "hashtag": "#community", "slug": "community", "year": null, "description": "Initiatives in the Rust community." },
{ "id": 2, "name": "Computer Science", "hashtag": "#compsci", "slug": "computer-science", "year": null, "description": "Covering data structures, algorithms, memory safety, etc." },
{ "id": 3, "name": "Crates", "hashtag": "#crates", "slug": "crates", "year": null, "description": "Notable new or updated crates." },
{ "id": 4, "name": "DevOps and Deployment", "hashtag": "#devops", "slug": "devops-and-deployment", "year": null, "description": "Building and deploying Rust, containerisation, continuous integration, etc." },
{ "id": 5, "name": "Embedded", "hashtag": "#embedded", "slug": "embedded", "year": null, "description": "Rust on microcontrollers, IoT, devices." },
{ "id": 6, "name": "Games and Graphics", "hashtag": "#graphics", "slug": "games-and-graphics", "year": null, "description": "Games built with Rust and other graphics related work." },
{ "id": 7, "name": "Getting Started", "hashtag": "#starting", "slug": "getting-started", "year": null, "description": "Introductory posts, guides and tutorials for getting started with Rust." },
{ "id": 8, "name": "Language", "hashtag": "#language", "slug": "language", "year": null, "description": "General posts about the Rust language." },
{ "id": 9, "name": "Operating Systems", "hashtag": "#os", "slug": "operating-systems", "year": null, "description": "Using Rust to build or explore operating systems." },
{ "id": 10, "name": "Performance", "hashtag": "#performance", "slug": "performance", "year": null, "description": "Optimisation, benchmarks, etc." },
{ "id": 11, "name": "Rust 2018", "hashtag": "#Rust2018", "slug": "rust-2018", "year": 2018, "description": "Hopes and dreams for Rust in 2018." },
{ "id": 12, "name": "Rust 2019", "hashtag": "#rust2019", "slug": "rust-2019", "year": 2019, "description": "Ideas from the community for Rust in 2019, and the next edition." },
{ "id": 16, "name": "Rust 2020", "hashtag": "#rust2020", "slug": "rust-2020", "year": 2020, "description": "Ideas from the Rust community and picking a theme for 2020." },
{ "id": 13, "name": "Tools and Applications", "hashtag": "#tools", "slug": "tools-and-applications", "year": null, "description": "Command line tools and GUI applications written in or for Rust." },
{ "id": 14, "name": "Security", "hashtag": "#security", "slug": "security", "year": null, "description": "Security, cryptography, etc." },
{ "id": 15, "name": "Web and Network Services", "hashtag": "#web", "slug": "web-and-network-services", "year": null, "description": "Web applications, web assembly, network daemons, etc." }
]
@@ -4,6 +4,7 @@ class Category
name: String,
hashtag: String,
slug: String,
year: UInt16?,
description: String,
)

@@ -16,6 +16,8 @@ class Categories::ShowPage < MainLayout
end
end

maybe_include_post_count(@category.year, @posts)

@posts.each do |post|
article do
a post.title, href: post.url
@@ -27,4 +29,15 @@ class Categories::ShowPage < MainLayout
end
end
end

private def maybe_include_post_count(year : UInt16?, posts : PostQuery)
if year
post_count = posts.clone.select_count
if year < Time.utc.year + 1
para "#{pluralize(post_count, "post")} were made by the Rust commmunity:"
else
para "#{pluralize(post_count, "post")} have been made by the Rust commmunity:"
end
end
end
end

0 comments on commit 15cceb7

Please sign in to comment.
You can’t perform that action at this time.