Skip to content

Instantly share code, notes, and snippets.

@zvlex
Created May 22, 2014 17:59
Show Gist options
  • Save zvlex/30af843b2313c0638442 to your computer and use it in GitHub Desktop.
Save zvlex/30af843b2313c0638442 to your computer and use it in GitHub Desktop.
Jekyll-s rake post:new
namespace :post do
desc 'create a new jekyll post'
task :new do
title = ENV['title']
time = Time.now
slug = "#{time.strftime("%Y-%m-%d")}#{title.downcase.gsub(/[^\w]+/, '-')}"
file = File.join(
File.dirname(__FILE__),
'_posts',
slug + '.markdown'
)
File.open(file, "w") do |f|
f << <<-EOS.gsub(/^ /, '')
---
layout: post
title: #{title}
date: #{time.strftime("%Y-%m-%d %H:%M:%S")}
categories: []
---
EOS
end
puts "#{file} created! - ok"
system ("#{ENV['EDITOR']} #{file}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment