Skip to content

Instantly share code, notes, and snippets.

@tonytonyjan
Created May 2, 2012 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonytonyjan/2574782 to your computer and use it in GitHub Desktop.
Save tonytonyjan/2574782 to your computer and use it in GitHub Desktop.
A useful rake task of Octopress for listing published or unpublished posts.
# 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