Added option to specify time when creating posts
This commit is contained in:
parent
12e4175188
commit
02e2f861e7
1 changed files with 3 additions and 2 deletions
5
Rakefile
5
Rakefile
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue