Created
October 1, 2012 21:29
-
-
Save freegenie/3814550 to your computer and use it in GitHub Desktop.
A simple script to automate blog posting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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