Skip to content

Commit f52ff5a

Browse files
committed
Refactor new post rake task
Rename from 'rake new_post' to 'rake post'. Also use environment variables over rake arguments
1 parent 0fec345 commit f52ff5a

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

Diff for: Rakefile

+7-8
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ CONFIG = {
99
'post_ext' => "md"
1010
}
1111

12-
# usage rake new_post[my-new-post] or rake new_post['my new post'] or rake new_post (defaults to "new-post")
12+
# Usage: rake post title="A Title"
1313
desc "Begin a new post in #{CONFIG['posts']}"
14-
task :new_post, :title do |t, args|
14+
task :post do
1515
abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts'])
16-
args.with_defaults(:title => 'new-post')
17-
slug = args.title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
16+
title = ENV["title"] || "new-post"
17+
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
1818
filename = File.join(CONFIG['posts'], "#{Time.now.strftime('%Y-%m-%d')}-#{slug}.#{CONFIG['post_ext']}")
1919
if File.exist?(filename)
2020
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|
2424
open(filename, 'w') do |post|
2525
post.puts "---"
2626
post.puts "layout: post"
27-
post.puts "title: \"#{args.title.gsub(/-/,' ')}\""
28-
post.puts "comments: true"
27+
post.puts "title: \"#{title.gsub(/-/,' ')}\""
2928
post.puts "category: "
3029
post.puts "tags: []"
3130
post.puts "---"
32-
page.puts "{% include JB/setup %}"
31+
post.puts "{% include JB/setup %}"
3332
end
34-
end # task :new_post
33+
end # task :post
3534

3635
desc "Switch between Jekyll-bootstrap themes."
3736
task :switch_theme, :theme do |t, args|

0 commit comments

Comments
 (0)