Skip to content

Instantly share code, notes, and snippets.

@joshkerr
Created February 21, 2011 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshkerr/836722 to your computer and use it in GitHub Desktop.
Save joshkerr/836722 to your computer and use it in GitHub Desktop.
Ruby rake file for creating a new post for Jekyll static blogs
desc 'Begin a new post'
task :post do
ROOT_DIR = File.dirname(__FILE__)
title = ARGV[1]
tags = ARGV[2 ]
unless title
puts %{Usage: rake post "The Post Title"}
exit(-1)
end
datetime = Time.now.strftime('%Y-%m-%d') # 30 minutes from now.
slug = title.strip.downcase.gsub(/ /, '-')
# E.g. 2006-07-16_11-41-batch-open-urls-from-clipboard.markdown
path = "#{ROOT_DIR}/_posts/#{datetime}-#{slug}.markdown"
header = <<-END
---
layout: post
title: #{title}
excerpt:
category:
---
END
File.open(path, 'w') {|f| f << header }
system("mate", path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment