Added option to specify time when creating posts

This commit is contained in:
Andrea Schiavini 2012-02-08 14:45:46 +01:00 committed by Jade Dominguez
parent 12e4175188
commit 02e2f861e7

View file

@ -39,13 +39,14 @@ module JB
end #Path
end #JB
# Usage: rake post title="A Title"
# Usage: rake post title="A Title" date="2012-02-09"
desc "Begin a new post in #{CONFIG['posts']}"
task :post do
abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts'])
title = ENV["title"] || "new-post"
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
filename = File.join(CONFIG['posts'], "#{Time.now.strftime('%Y-%m-%d')}-#{slug}.#{CONFIG['post_ext']}")
date = ENV['date'] || Time.now.strftime('%Y-%m-%d')
filename = File.join(CONFIG['posts'], "#{date}-#{slug}.#{CONFIG['post_ext']}")
if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
end