Skip to content

Instantly share code, notes, and snippets.

@jteneycke
Forked from bru/newpost.rb
Created October 14, 2012 19:10
Show Gist options
  • Save jteneycke/3889526 to your computer and use it in GitHub Desktop.
Save jteneycke/3889526 to your computer and use it in GitHub Desktop.
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