Keeping track of dates is hard, why not let the computer do it for you ;-) Previously when I wanted to create a new post I would simply copy an old one and rename it. But the name and date appears in two locations, part of the filename and also in the front matter section. Sounds like a script to me, generally I would go to bash, but I want to brush up on RUBY, pregnant pause be damned.

The goal here is to create a script in which i would simply pass it the title, and it will use the current time as the date stamp, create the file, populate the front matter section with the same title and date stamp, this time with time, and have some dummy content.

And while we are at it, adding quotations around the title is way to much work, so we will assume all the arguments are actually the title.

$ ~/bin/new-post.rb Now is the time to create a post
#!/usr/bin/ruby
# Create a new post using current time as date stamp

NOW       = Time.now
TITLE     = ARGV.join ' ' 
DATE      = NOW.strftime "%F %T %z" 
FILENAME  = NOW.strftime("%F-") + TITLE.gsub(/\s+/,'-') + ".markdown"

CONTENT   =<<EOT
---
layout: post
title: "#{TITLE}"
date: #{DATE}
categories: new 
---
BODY 

{% highlight shell %}
$ whoami
{% endhighlight %}

[example]: https://example.com
EOT

File.write FILENAME, CONTENT