As you can tell, I’ve switched this blog from Jekyll to Hugo since its entire toolchain comes in a single downloadable binary. I don’t need bells and whistles, and the Paper theme makes it look like I still know how to make pretty things.

While Hugo has the hugo new generator, and it works really well, I wanted to preserve the hugo import jekyll migrated filename pattern. Time for a new skeleton script, this time in ruby because I used bash in the last one.

#!/usr/bin/env ruby

if ARGV.empty? || ARGV[0] == '-h'
  puts "Generate a new blog post for Hugo."
  puts "Usage: ./new-post full blog post title"
  exit false
end

now = Time.now.utc
blog_title = ARGV.join(' ')
file_path = blog_title.downcase.gsub(/[^0-9a-z]+/, '-')
file_path = "content/#{now.strftime('%Y-%m-%d')}-#{file_path}.md"
blog_date = now.strftime("%Y-%m-%dT%H:%M:%SZ")

if File.exist? file_path
  puts "Post #{file_path} already exists!"
  exit false
end

File.open(file_path, 'w') do |fp|
  fp.puts "---"
  fp.puts "title: \"#{blog_title}\""
  fp.puts "date: \"#{blog_date}\""
  fp.puts "comments: false"
  fp.puts "draft: true"
  fp.puts "---"
end

puts "Created post '#{blog_title}' as #{file_path}"

Maybe a little less code than the bash version, maybe a little easier to read.