Using Hugo archetypes with 11ty

A few months ago I rebuilt my site to use 11ty instead of Hugo. One feature of Hugo I’ve missed is Archetypes, which lets you create new posts and pages from templates. I had it on my list to recreate this in Node or write a bash script but I haven’t gotten around to it yet. Today I realized that there’s no reason I can’t use Hugo’s archetypes system with 11ty—I keep Hugo installed on my system to work on other projects, and it doesn’t need much to use archetypes.

I added archetypes/blog.md to my project root. The contents of that file looks like this:

---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
tags:
-
draft: true

---

And I updated .gitignore to exclude Hugo’s lockfile:

/.hugo_build.lock

Then in the terminal, I run hugo new content/blog/post-name.md and I get a new blank post with “Post Name” as the title, and the current date/time prepopulated in ISO 8601 format.

To make things even better, I added hugo.toml to configure which editor Hugo should open with the new post:

newContentEditor = "subl"
[security]
[security.exec]
allow = ['^subl$']

This is an unholy abomination and I should write a script to do all this instead, but it works well and I like how silly it is.