Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Source updated at 2012-05-02 07:48:16 UTC

  • Loading branch information...
commit 99f9fc2d07dddc21f40dfbf2cd3ffbca2b770dd0 1 parent 4f224e4
@tonytonyjan authored
View
0  .preview-mode
No changes.
View
40 Rakefile
@@ -375,3 +375,43 @@ task :list do
puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).join(', ')}"
puts "(type rake -T for more detail)\n\n"
end
+
+desc "Short cut for pushing source, generating and deploying website"
+task :go do
+ # push source
+ system "git add ."
+ system "git add -u"
+ system "git status"
+ message = "Source updated at #{Time.now.utc}"
+ system "git commit -m \"#{message}\""
+ system "git push origin source"
+ # deploy
+ system "set LANG=zh_TW.UTF-8"
+ system "set LC_ALL=zh_TW.UTF-8"
+ Rake::Task[:generate].execute
+ Rake::Task[:deploy].execute
+end
+
+# 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
View
20 source/_posts/2012-05-02-list-all-posts-rake-task-for-octopress.markdown
@@ -0,0 +1,20 @@
+---
+layout: post
+title: "List Published or Unpublished Posts in Octopress"
+date: 2012-05-02 13:36
+comments: true
+categories: Octopress
+---
+
+## What's the Problem?
+
+We may leave some draft posts in `_posts` directory, but it comes a problem when we are going to find whether the post is published or not by reading throuh filenames in the future.
+
+To solve this, I created this rake task. It will list all posts each line, and prepend an asterisk if it's published. Just append it in your `Rakefile` to make it works.
+
+### Usage
+
+ rake list_posts
+ rake list_posts[pub|unpub]
+
+{% gist 2574782 %}
View
BIN  source/images/birds2.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.