Skip to content

Instantly share code, notes, and snippets.

@freegenie
Created October 1, 2012 21:29
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 freegenie/3814550 to your computer and use it in GitHub Desktop.
Save freegenie/3814550 to your computer and use it in GitHub Desktop.
A simple script to automate blog posting
#!/usr/bin/env /Users/fregini/.rbenv/versions/1.9.2-p318/bin/ruby
#
# A simple script to automate the creation of a new blog post.
# An automator task will pick the file name in output and open
# it with the default editor.
#
require 'rubygems'
require 'active_support/all'
require 'pathname'
date = Date.today.strftime('%Y-%m-%d')
nice_title = ARGV.join ' '
title = ARGV.join '-'
title = "#{date}-#{title.dasherize.downcase}"
new_file_name = "#{title}.md"
post_source_dir = Pathname.new "~/Work/freegenie.github.com/_posts/"
template = post_source_dir.join('template.md').expand_path
new_file_path = post_source_dir.join(new_file_name).expand_path
template_content = File.read(template)
File.open(new_file_path, 'w') do |f|
f.write template_content.
gsub('{{title}}', nice_title).
gsub('{{date}}', date)
end
puts new_file_path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment