Skip to content

Instantly share code, notes, and snippets.

@rococodogs
Last active May 31, 2017 16:57
Show Gist options
  • Save rococodogs/b79061f4ea104feb28659cd436990f78 to your computer and use it in GitHub Desktop.
Save rococodogs/b79061f4ea104feb28659cd436990f78 to your computer and use it in GitHub Desktop.
rake task for creating a bare jekyll post
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