Jekyll is great. But creating posts files with names like “” calls out to be scripted.

This is an image

At one point I’d written a simple script to create new posts in jekyll.

For this reboot of the blog, I just googled and grabbed one that someone else had put in this gist.

There are other scripts. That do fancy things like take command line options. But this was fine. If I find I need more, I may rewrite it, or regoogle.

I made a couple of changes. I changed my path and my editor. And I added a timestamp to the frontmatter.

The timestamp in the frontmatter lets Jekyll sort posts chronologically if they were made on the same day.

So I ended up with this:

#!/usr/bin/env ruby

unless ARGV[0]
  puts 'Usage: newpost "the post title"'

date_prefix ="%Y-%m-%d")
postname = ARGV[0].strip.downcase.gsub(/ /, '-')
post = "/Users/jeff/dev/blog/jekyll/{date_prefix}-#{postname}.md"

header = <<-END
layout: post
title: "#{ARGV[0]}"
date: #{"%Y-%m-%d %H:%M:%S")}
END, 'w') do |f|
  f << header

system("vim", post)