Browse code

added a rake task for creating a new post

B Mathis authored on 07/12/2009 at 16:55:13
Showing 1 changed files
... ...
@@ -35,6 +35,18 @@ task :default => [:generate_site, :generate_style] do
35 35
   puts ">>> Site Generating Complete! <<<\n\n"
36 36
 end
37 37
 
38
+# usage rake post[my-new-post] or rake post['my new post'] or rake post (defaults to "new-post")
39
+desc "Begin a new post in #{source}/_posts"
40
+task :post, :filename do |t, args|
41
+  args.with_defaults(:filename => 'new-post')
42
+  #system "touch #{source}/_posts/#{Time.now.strftime('%Y-%m-%d_%H-%M')}-#{args.filename}.markdown"
43
+  open("#{source}/_posts/#{Time.now.strftime('%Y-%m-%d_%H-%M')}-#{args.filename.gsub(/[ _]/, '-')}.markdown", 'w') do |post|
44
+    post.puts "---"
45
+    post.puts "title: \"#{args.filename.gsub(/[-_]/, ' ').titlecase}\""
46
+    post.puts "---"
47
+  end
48
+end
49
+
38 50
 desc "list tasks"
39 51
 task :list do
40 52
   puts "Tasks: #{(Rake::Task.tasks - [Rake::Task[:list]]).to_sentence}"