As an improvement on an older shell script, here’s a rake task to list all of the categories in your blog, along with post counts for each of them:
12345678910111213141516171819202122
desc"count the number of posts in each category"task:count_categoriesdorequire'yaml'counts={}Dir.glob('source/_posts/*.markdown').eachdo|f|post=beginYAML.load(File.open(f))rescueArgumentError=>eputs"error: parsing #{f} - #{e.message}"endcats=post['categories']ifcats.respond_to?"each"cats.each{|c|counts[c]=counts[c].to_i+1}elsecounts[cats]=counts[cats].to_i+1endendcounts.sort_by{|k,v|v}.reverse.each{|k,v|puts"#{v}#{k}"}end
Just add this to the end of your OctoPress Rakefile and you’re good to go.