If you are using categories on your blog like…
activate :blog do |options| options.sources = "writing/{year}{month}{day}-{title}.html" options.permalink = "writing/{year}/{month}/{day}/{title}" options.taglink = "tags/{tag}/index.html" options.tag_template = "partials/components/templates/tag.html" options.new_article_template = "source/partials/components/templates/article.html.erb" options.layout = "article" options.default_extension = ".slim" options.custom_collections = { category: { link: "/categories/{category}/index.html", template: 'partials/components/templates/category.html' } } end
I setup up this helper to build you an array of categories with their associate post counts…
def build_categories categories = [] blog.articles.each do |article| category = {category: article.metadata[:page]['category'], category_count: 0} unless categories.find {|c| c[:category] == category[:category]} categories.push(category) end current_count = categories.find {|c| c[:category] == category[:category]}[:category_count] categories.find {|c| c[:category] == category[:category]}[:category_count] = current_count += 1 end return categories.sort_by!{ |category| category.count }.reverse end