Last active
September 24, 2015 16:11
-
-
Save shotasenga/802c2f0a93cd46bda3a4 to your computer and use it in GitHub Desktop.
Octopress Rake Task for list categories that used on the blog.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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