Skip to content

Instantly share code, notes, and snippets.

@druttka
Created April 2, 2014 03:45
Show Gist options
  • Save druttka/9927637 to your computer and use it in GitHub Desktop.
Save druttka/9927637 to your computer and use it in GitHub Desktop.
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