Breyten Ernsting

Webdeveloper at Open State Foundation.

Automatically Create Draft Posts Using Octopress

Octopress has support for draft posts, which is covered in the documentation.

You mark a post as a draft using the published directive:

1
published: false

However, new posts do not include this directive. In order to change this behaviour, you have to edit the Rakefile. Scroll to the :new_post task. At the end of the task there are a couple of lines which write the YAML front matter into the file. You can add more directives there. I’ve put the published directive just after the comments directive. It looks like this:

1
2
3
4
5
6
7
8
9
10
11
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
  post.puts "---"
  post.puts "layout: post"
  post.puts "title: \"#{title.gsub(/&/,'&')}\""
  post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}"
  post.puts "comments: true"
  post.puts "published: false"
  post.puts "categories: "
  post.puts "---"
end

Now all new posts will be draft posts. Just make sure you don’t forget to mark them as published after you’re done editing.

Comments