Created
May 2, 2012 07:25
-
-
Save tonytonyjan/2574782 to your computer and use it in GitHub Desktop.
A useful rake task of Octopress for listing published or unpublished posts.
This file contains 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
# usage rake new_page[my-new-page] or rake new_page[my-new-page.html] or rake new_page (defaults to "new-page.markdown") | |
desc "List all posts with an asterisk if it's published. Advanced usage: 'rake list_posts[pub|unpub]'" | |
task :list_posts, :type do |t, args| | |
type = args.type | |
result = "" | |
Dir.glob("#{source_dir}/#{posts_dir}/*.markdown").sort.each do |post| | |
file = File.read(post) | |
file =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m | |
data = YAML.load($1) | |
case type | |
when "pub" then | |
result << "#{File.basename(post)}\n" if data['published'] || data['published'] == nil | |
when "unpub" | |
result << "#{File.basename(post)}\n" if data['published'] == false | |
else | |
status = data['published'] || data['published'] == nil ? '*' : ' ' | |
result << "#{status} #{File.basename(post)}\n" | |
end | |
end | |
puts result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment