Last active
June 4, 2018 07:51
-
-
Save zouchao/4775cabea1a909844e11378de7c82d72 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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