Last active
May 31, 2017 16:57
-
-
Save rococodogs/b79061f4ea104feb28659cd436990f78 to your computer and use it in GitHub Desktop.
rake task for creating a bare jekyll post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "date" | |
namespace :post do | |
desc "creates a new post file" | |
task :new do | |
now = Time.new | |
title = ARGV.last | |
slugified = title.downcase.gsub(/\s+/, '-') | |
filename = "#{now.to_date}-#{slugified}.markdown" | |
contents = "---\n" | |
contents << "layout: post\n" | |
contents << "title: #{title}\n" | |
contents << "date: #{now}\n" | |
contents << "published: false\n" | |
contents << "---\n\n" | |
file = File.new("./_posts/#{filename}", "w") | |
file.write(contents) | |
file.close | |
# fake a task so Rake doesn't complain | |
# see https://itshouldbeuseful.wordpress.com/2011/11/07/passing-parameters-to-a-rake-task/ | |
task title.to_sym do ; end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment