blogpost

This blog is generated by Hugo, a static site generator. It works great! One of the things I like best about it is that it supports Org. That is, I can write posts in org-mode instead of markdown. Normally, you would create a new post with something like

❯ hugo new posts/foo.org
/home/tim/blog/content/posts/foo.org created

The file created has a Hugo header already in it.

❯ cat content/posts/foo.org 
---
title: "Foo"
date: 2021-09-21T14:01:43-04:00
draft: true
---

The problem is, this isn't valid Org. I really want it to say

 #+title: "Foo"
 #+date: 2021-09-21T14:01:43-04:00
 #+draft: true

I couldn't figure out how to get hugo new to do that for me. Also, I don't really want it to create content/posts/foo.org, but content/posts/foo/index.org. That way I can put images and things that go with that post in the foo directory too. Finally, I don't really need the time and offset, just the date.

I ended up writing blogpost, a little program that does all these things.

❯ blogpost --title=foo
❯ cat content/posts/foo/index.org 
 #+title: foo
 #+date: 2021-09-21
 #+draft: false
 #+tags[]:

In fact, the current date is usually what I want foo to be too, so I made that the default.

❯ blogpost
❯ cat content/posts/20210921/index.org 
 #+title: 20210921
 #+date: 2021-09-21
 #+draft: false
 #+tags[]:

I also gave it a --tags option for adding tags.

❯ blogpost --help
blogpost 0.1.0

Tim Heaney <oylenshpeegul@pm.me>

USAGE:
    blogpost [FLAGS] [OPTIONS]

FLAGS:
        --debug      Debug mode
        --draft      Mark the new post as a draft?
    -h, --help       Print help information
    -v, --verbose    Verbose mode (-v, -vv, -vvv, etc.)
    -V, --version    Print version information

OPTIONS:
    -d, --dir <DIR>        Create the new post in this directory [default: ./content/posts]
    -t, --title <TITLE>    Title of new post (default: today's date)
        --tags <TAGS>      Tags are space-separated words [default: " "]