Skip to content

Instantly share code, notes, and snippets.

@kumabook
Created March 8, 2016 12:05
Show Gist options
  • Save kumabook/2507546ff9004df76e84 to your computer and use it in GitHub Desktop.
Save kumabook/2507546ff9004df76e84 to your computer and use it in GitHub Desktop.
Create jekyll new post
require 'erb'
title = ARGV[0]
categories = ARGV[1]
now = Time.new()
file_name = "#{now.strftime('%Y-%m-%d')}-#{title}.markdown"
puts "title: #{file_name}"
erb = ERB.new <<'END'
---
layout: post
title: "<%= title %>"
date: <%= now.strftime('%Y-%m-%d %H:%M:%S %z') %>
categories: <%= categories %>
---
END
body = erb.result
path = "_posts/#{file_name}"
if File.exists?(path)
puts "#{path} already exists"
else
File.write(path, body)
puts "#{path} is genrated!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment