Created
August 30, 2017 23:51
-
-
Save dmitryrck/fed691effd914ac0609bcbbab9f7b373 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ruby | |
if ARGV.size.zero? || ["--help", "-h"].include?(ARGV[0]) | |
puts %Q[Usage: #{__FILE__} "My Title Here"] | |
exit 1 | |
end | |
slug = ARGV[0].downcase.gsub(/[^a-z1-9]+/, "-").chomp("-") | |
def format_number(number) | |
number.to_s.rjust(2, "0") | |
end | |
current = Time.new | |
year = current.year | |
month = format_number(current.month) | |
day = format_number(current.day) | |
date = [year, month, day].join("-") | |
time = %Q[#{format_number(current.hour)}:#{format_number(current.min)}] | |
filename = "#{ARGV[1] || "."}/_posts/#{date}-#{slug}.markdown" | |
string =<<EOF | |
--- | |
layout: post | |
title: "#{ARGV[0]}" | |
date: #{date} #{time} | |
comments: true | |
categories: | |
--- | |
EOF | |
File.open(filename, "w") do |file| | |
file.write(string) | |
file.close | |
end | |
puts filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment