Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix for the error on post creation if date was not specified.
  • Loading branch information
alishutc authored and plusjade committed Mar 7, 2012
1 parent cefdd4e commit 9a69c8e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Rakefile
Expand Up @@ -40,19 +40,19 @@ module JB
end #Path
end #JB

# Usage: rake post title="A Title" date="2012-02-09"
# 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-]/, '')
begin
date = (Time.parse(ENV['date']) || Time.now).strftime('%Y-%m-%d')
date = (ENV['date'] ? Time.parse(ENV['date']) : Time.now).strftime('%Y-%m-%d')
rescue Exception => e
puts "Error - date format must be YYYY-MM-DD, please check you typed it correctly!"
exit -1
end
filename = File.join(CONFIG['posts'], "#{date}-#{slug}.#{CONFIG['post_ext']}")
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
Expand Down

0 comments on commit 9a69c8e

Please sign in to comment.