Skip to content

Instantly share code, notes, and snippets.

@MattHall
Created February 11, 2012 15:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MattHall/1801090 to your computer and use it in GitHub Desktop.
Save MattHall/1801090 to your computer and use it in GitHub Desktop.
Rake task for creating new posts in Jekyll
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