Skip to content

Instantly share code, notes, and snippets.

@return-none
Last active December 14, 2015 18:59
Show Gist options
  • Save return-none/5132887 to your computer and use it in GitHub Desktop.
Save return-none/5132887 to your computer and use it in GitHub Desktop.
Rakefile for new post Jekyll blogging
# Original idea by MattHall
# https://gist.github.com/MattHall/1801090
# usage rake new_post title="my awesome title"
require 'date'
task :new_post do
title = ENV['title']
path = "_posts/#{Date.today}-#{title.downcase.gsub(/[^[:alnum:]]+/, '-')}.md"
if File.exist?(path)
puts "[WARN] File exists - skipping create"
else
File.open(path, 'w') do |file|
file.puts '---'
file.puts 'layout: default'
file.puts 'title: ' + title.capitalize
file.puts '---'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment