Skip to content

Instantly share code, notes, and snippets.

@shotasenga
Last active September 24, 2015 16:11
Show Gist options
  • Save shotasenga/802c2f0a93cd46bda3a4 to your computer and use it in GitHub Desktop.
Save shotasenga/802c2f0a93cd46bda3a4 to your computer and use it in GitHub Desktop.
Octopress Rake Task for list categories that used on the blog.
desc "List categories from existing posts (#{source_dir}/#{posts_dir}/*#{new_post_ext})"
task :categories do
categories = []
tags = []
Dir.glob("./#{source_dir}/#{posts_dir}/*.markdown") do |path|
content = File.read(path)
next unless content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
data = YAML.load($1)
categories.push data["categories"] if data["categories"]
tags.push data["tags"] if data["tags"]
end
puts "Categories"
puts categories.flatten.uniq.sort.map{|d| '- ' + d}.join("\n")
end
$ rake categories
Categories
- Chrome
- Flex
- Git
- HTML5
- Mac
- Octopress
- Others
- PHP
- Ruby
- Vagrant
- WordPress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment