Skip to content

Instantly share code, notes, and snippets.

@jteneycke jteneycke/newpost.rb forked from bru/newpost.rb
Created Oct 14, 2012

Embed
What would you like to do?
Creates a new Jekyll post, opens it in Geany, and adds to the git index
#!/usr/bin/env ruby
require Dir
unless ARGV[0]
puts 'Usage: newpost "the post title"'
exit(-1)
end
blog_root = "/Users/jrk/proj/blog"
date_prefix = Time.now.strftime("%Y-%m-%d")
postname = ARGV[0].strip.downcase.gsub(/ /, '-')
post = "#{blog_root}/_posts/#{date_prefix}-#{postname}.md"
header = <<-END
---
layout: post
title: "#{ARGV[0]}"
---
END
Dir.chdir(blog_root)
File.open(post, 'w') do |f|
f << header
end
system("geany", post)
system("git", "add", post)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.