Skip to content

Instantly share code, notes, and snippets.

@henrrrik
Forked from bru/newpost.rb
Created January 25, 2012 18:26
Show Gist options
  • Save henrrrik/1677739 to your computer and use it in GitHub Desktop.
Save henrrrik/1677739 to your computer and use it in GitHub Desktop.
Creates a new Jekyll post, opens it in MacVim, and adds to the git index
#!/usr/bin/env ruby
unless ARGV[0]
puts 'Usage: newpost "the post title"'
exit(-1)
end
blog_root = "/Users/henrik/Project/henrrrik.github.com"
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]}"
created: #{Time.now.utc.to_i}
---
END
Dir.chdir(blog_root)
File.open(post, 'w') do |f|
f << header
end
system("mvim", post)
system("git", "add", post)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment