Creating a New Post in Jekyll with Rake
11 Feb 2012
Just a quick and dirty rake task that lets you run this:
rake np -- The Post Title
…to set up a new post in Jekyll and open it in Sublime Text 2.
If you prefer another editor, then swap the subl command for the appropriate CLI command for your editor.
require 'rubygems'
require 'optparse'
require 'yaml'
task :np do
OptionParser.new.parse!
ARGV.shift
title = ARGV.join(' ')
path = "_posts/#{Date.today}-#{title.downcase.gsub(/[^[:alnum:]]+/, '-')}.markdown"
if File.exist?(path)
puts "[WARN] File exists - skipping create"
else
File.open(path, "w") do |file|
file.puts YAML.dump({'layout' => 'post', 'published' => false, 'title' => title})
file.puts "---"
end
end
`subl #{path}`
exit 1
end
Also available here as a gist.