Skip to content

Instantly share code, notes, and snippets.

@zouchao
Last active June 4, 2018 07:51
Show Gist options
  • Save zouchao/4775cabea1a909844e11378de7c82d72 to your computer and use it in GitHub Desktop.
Save zouchao/4775cabea1a909844e11378de7c82d72 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "pathname"
unless ARGV[0]
puts 'Usage: newpost "the post title"'
exit(-1)
end
date_prefix = Time.now.strftime("%Y-%m-%d")
postname = ARGV[0].strip.downcase.gsub(/ /, '-')
post = Pathname(__FILE__).dirname + "_posts" + "#{date_prefix}-#{postname}.md"
header = <<-END
---
date: #{Time.new.strftime('%F %T')}
title: #{ARGV[0]}
layout: post
tags:
-
categories:
-
---
END
File.open(post, 'w') do |f|
f << header
end
system("#{ENV['EDITOR']}", post.to_s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment