Here is the little rake task I use to create new posts for the WiseCash jekyll-based blog.
To use, just run:
rake blog:new["Your Blog Post Title"]
namespace :blog do | |
task :new, [:title] => :environment do |t, args| | |
today = Date.today.to_s | |
title = args[:title] | |
if title.blank? | |
abort("\nPlease specify a title, eg:\n\nrake blog:new[\"Freelance Cash Flow: 10 Tips for a Happier Freelancing\"]\n\n") | |
end | |
slug = title.parameterize | |
folder = File.join(File.dirname(__FILE__), '..', '..', 'blog', 'src', '_posts') | |
filename = File.join(folder, [today, slug].join('-')) + '.markdown' | |
config = { | |
'layout' => 'post', | |
'title' => title, | |
'date' => today | |
} | |
if File.exist?(filename) | |
abort("File #{filename} already exists! Aborting.") | |
else | |
File.open(filename, 'w') do |file| | |
file << config.to_yaml | |
file << "---\n" | |
file << "\n\nPut the summary here\n\n" | |
file << "<!--more-->" | |
file << "\n\nPut the next part here\n\n" | |
end | |
end | |
end | |
end |