summaryrefslogtreecommitdiff
path: root/Rakefile
diff options
context:
space:
mode:
authorJade Dominguez <plusjade@gmail.com>2012-01-23 02:31:42 -0800
committerJade Dominguez <plusjade@gmail.com>2012-01-23 02:31:42 -0800
commitf52ff5aa62f0b1ecebac14f8556b60550a3a8712 (patch)
tree5a882b982d3da50dffbce2991ba2ba880759045f /Rakefile
parent0fec345989bfdfb127d1397973d89046b03f5ced (diff)
Refactor new post rake task
Rename from 'rake new_post' to 'rake post'. Also use environment variables over rake arguments
Diffstat (limited to 'Rakefile')
-rw-r--r--Rakefile15
1 files changed, 7 insertions, 8 deletions
diff --git a/Rakefile b/Rakefile
index 6b750d8..3d98d0c 100644
--- a/Rakefile
+++ b/Rakefile
@@ -9,12 +9,12 @@ CONFIG = {
'post_ext' => "md"
}
-# usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")
+# Usage: rake post title="A Title"
desc "Begin a new post in #{CONFIG['posts']}"
-task :new_post, :title do |t, args|
+task :post do
abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts'])
- args.with_defaults(:title => 'new-post')
- slug = args.title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
+ 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']}")
if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
@@ -24,14 +24,13 @@ task :new_post, :title do |t, args|
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: post"
- post.puts "title: \"#{args.title.gsub(/-/,' ')}\""
- post.puts "comments: true"
+ post.puts "title: \"#{title.gsub(/-/,' ')}\""
post.puts "category: "
post.puts "tags: []"
post.puts "---"
- page.puts "{% include JB/setup %}"
+ post.puts "{% include JB/setup %}"
end
-end # task :new_post
+end # task :post
desc "Switch between Jekyll-bootstrap themes."
task :switch_theme, :theme do |t, args|