Skip to content

Instantly share code, notes, and snippets.

@mrchrisadams
Forked from al3x/newpost.rb
Created December 17, 2009 00:47
Show Gist options
  • Save mrchrisadams/258386 to your computer and use it in GitHub Desktop.
Save mrchrisadams/258386 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
unless ARGV[0]
puts 'Usage: newpost "the post title"'
exit(-1)
end
# set the date for the entry, where the jekyll blog is and process the title to give a filename:
date_prefix = Time.now.strftime("%Y-%m-%d")
postname = ARGV[0].strip.downcase.gsub(/ /, '-')
jekyll_path = '/Users/chrisadams/GitRepos/camuk'
# then construct the full path
post = "#{jekyll_path}/#{date_prefix}-#{postname}.markdown"
# set basic meta data
header = <<-END
---
layout: post
title: "#{ARGV[0]}"
---
# {{ page.title }}
END
File.open(post, 'w') do |f|
f << header
end
# finally, open the newly created file in Textmate for editing fun
system("mate", "-a", post)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment