Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor new post rake task

Rename from 'rake new_post' to 'rake post'. Also use environment variables over rake arguments
  • Loading branch information...
commit f52ff5aa62f0b1ecebac14f8556b60550a3a8712 1 parent 0fec345
@plusjade plusjade authored
Showing with 7 additions and 8 deletions.
  1. +7 −8 Rakefile
View
15 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|
Please sign in to comment.
Something went wrong with that request. Please try again.