Skip to content

Instantly share code, notes, and snippets.

@jamesnesfield
Last active August 29, 2015 14:08
Show Gist options
  • Save jamesnesfield/61190f8e484a037083b6 to your computer and use it in GitHub Desktop.
Save jamesnesfield/61190f8e484a037083b6 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
if ARGV.empty?
puts "Usage: ruby make-new-post.rb SLUG"
exit
end
POST_DIR = "/PATH/TO/YOUR/DEAL" # no trailing slash
date = Time.now.strftime("%Y-%m-%d")
slug = ARGV[0]
# the layout/category/permalink values are, of course, specific to my setup
new_file = <<MONKEYTIME
---
layout: note
category: note
date: #{date}
title: TITLE_HERE
permalink: note/#{slug}
---
Put your markdown here, dude
MONKEYTIME
filename = "#{POST_DIR}/#{date}-#{slug}.md"
if !File.exist?(filename) then
File.open(filename, "w") { |file| file.write(new_file) }
# i think iA Writer is nearly perfect for this but obv you can substitute something else
spawn "open -a iA\\ Writer #{filename}"
puts "Made #{filename}, opened it in iA Writer"
else
puts "Error: that post already exists."
end
# optionally, put this in your .profile:
# newpostfunction() {
# ruby /PATH/TO/FILE/make-new-post.rb $1
# }
# alias newpost=newpostfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment