Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
desc "Begin a new draft in #{source_dir}/#{drafts_dir}"
task :new_draft, :title do |t, args|
title = args.title || get_stdin("Enter a title for the draft: ")
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
mkdir_p "#{source_dir}/#{drafts_dir}"
filename = "#{source_dir}/#{drafts_dir}/#{title.to_url}.#{new_post_ext}"
if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
end
puts "Creating new draft: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: post"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "comments: true"
post.puts "---"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment