Skip to content

Commit

Permalink
Added option to specify time when creating posts
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Schiavini authored and plusjade committed Mar 1, 2012
1 parent 12e4175 commit 02e2f86
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Rakefile
Expand Up @@ -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
Expand Down

0 comments on commit 02e2f86

Please sign in to comment.