Created
February 11, 2012 15:44
-
-
Save MattHall/1801090 to your computer and use it in GitHub Desktop.
Rake task for creating new posts in Jekyll
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment