Skip to content

Instantly share code, notes, and snippets.

@mlafeldt
Last active April 6, 2016 12:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlafeldt/4e5268b7024d1aaeb4aa to your computer and use it in GitHub Desktop.
Save mlafeldt/4e5268b7024d1aaeb4aa to your computer and use it in GitHub Desktop.
Rake task I use for starting a new article for Production Ready
require "stringex"
desc "Create a new letter"
task :new_letter, :title do |t, args|
title = args[:title] || "New Letter"
num = File::basename(Dir['letters/*'].last)[0,3].to_i + 1
filename = "letters/%03d-%s.md" % [num, title.to_url]
date = Time.now.strftime("%Y-%m-%d")
puts "==> Creating new letter: #{filename}"
content = <<EOS
---
title: "#{title.to_html(true)}"
subtitle:
date: #{date}
tags: []
medium:
photo:
mentions:
---
Add awesome content here.
EOS
File.write(filename, content)
git "checkout", "-b", title.to_url
git "add", filename
git "commit", "-m", "Add draft: #{title}"
open_in_editor(filename)
end
def open_in_editor(filename)
sh "open", "-a", "/Applications/Byword.app", filename
end
def git(*args)
sh "git", *args
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment