hugo org archetype

I love using Hugo to write. Their org-mode markup support is absolutely top notch. The only real problem with it is that while it's well supported, the Hugo docs don't cover it very much, as Markdown and TOML are the main markup and configuration languages.

One of the basic building blocks for Hugo blogs are Archetypes. Archetypes get used as the templates for new posts, and get automatically filled out with the title of the post and creation date.

Instead of writing the front matter of my posts in TOML, I use org-mode syntax, to keep the entire document uniformly org-ish.

To setup an org-mode archetype, create the file [site root]/archetypes/default.org with the following contents:

#+TITLE: {{ replace .Name "-" " " | title }}
#+DATE: {{ .Date }}
#+DRAFT: true
#+DESCRIPTION:
#+TAGS[]:
#+KEYWORDS[]:
#+SLUG:
#+SUMMARY:

While this template doesn't contain every predefined front matter variable, it contains all of the ones I use regularly. You can find a full list of predefined variables here. It doesn't hurt to have more variables in the template than you use, as empty variables are not used in the output. The org-mode front matter ends at the first line that doesn't start with #+.

The theme you use may also have its own custom front matter variables.

Now when I create a post, if the name of the post ends in .org, the default.org archetype file is used. For example to create this post, I ran

hugo new posts/hugo-org-archetype.org

Then I open it in Emacs and start typing!