Skip to content

Commit 9a69c8e

Browse files
alishutcplusjade
authored andcommittedMar 7, 2012
Fix for the error on post creation if date was not specified.
1 parent cefdd4e commit 9a69c8e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎Rakefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ module JB
4040
end #Path
4141
end #JB
4242

43-
# Usage: rake post title="A Title" date="2012-02-09"
43+
# Usage: rake post title="A Title" [date="2012-02-09"]
4444
desc "Begin a new post in #{CONFIG['posts']}"
4545
task :post do
4646
abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts'])
4747
title = ENV["title"] || "new-post"
4848
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
4949
begin
50-
date = (Time.parse(ENV['date']) || Time.now).strftime('%Y-%m-%d')
50+
date = (ENV['date'] ? Time.parse(ENV['date']) : Time.now).strftime('%Y-%m-%d')
5151
rescue Exception => e
5252
puts "Error - date format must be YYYY-MM-DD, please check you typed it correctly!"
5353
exit -1
5454
end
55-
filename = File.join(CONFIG['posts'], "#{date}-#{slug}.#{CONFIG['post_ext']}")
55+
filename = File.join(CONFIG['posts'], "##{date}-#{slug}.#{CONFIG['post_ext']}")
5656
if File.exist?(filename)
5757
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
5858
end

0 commit comments

Comments
 (0)
Please sign in to comment.