Skip to content

Instantly share code, notes, and snippets.

@sergeylukin
Created August 25, 2012 16:50
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 sergeylukin/3467823 to your computer and use it in GitHub Desktop.
Save sergeylukin/3467823 to your computer and use it in GitHub Desktop.
Ruby script for creating New Draft Post in Jekyll
#!/usr/bin/env ruby
unless ARGV[0]
puts 'Usage: newdraft "the draft title"'
exit(-1)
end
date_prefix = Time.now.strftime("%Y-%m-%d")
post_name = ARGV.join ' '
post_file_name = post_name.strip.downcase.gsub(/ /, '-')
post = "./_posts/#{date_prefix}-#{post_file_name}.draft.md"
header = <<-END
---
layout: post
tags:
title: "#{post_name}"
---
Write the "#{post_name}" content here...
END
File.open(post, 'w') do |f|
f << header
end
system("vim #{post}")
exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment