Hugo archetypes are the templates hugo new uses to stamp out a content file: some frontmatter, perhaps a placeholder body, with Go template variables for the title and date. Emet uses them the same way when you create an entry, and gives you a small editor for them so you don’t have to leave the CMS to change what a new post starts with.
Which archetype applies#
When you create an entry, Emet works out the section path from the folder you’re in. content/blog becomes blog, and content/en/resources/tutorials becomes resources/tutorials (the language prefix and any base_path are stripped). If you’ve drilled into a subfolder, that’s included too. It then tries, in order:
archetypes/resources/tutorials.mdarchetypes/resources-tutorials.mdarchetypes/resources.mdarchetypes/default.md- The same four under each theme’s
themes/<name>/archetypes/
The first file that exists wins. If none does, the entry starts with just title, date and draft: true, in YAML or TOML according to frontmatter_format in site.yaml.
In local development mode the dev server does the lookup, and it only tries the exact section path, its dashed form and default.md, so a parent section’s archetype isn’t picked up there.
Template variables#
Emet isn’t Hugo, so it can’t run arbitrary Go templates. It substitutes the handful of expressions archetypes actually use:
| Expression | Becomes |
|---|---|
{{ .Title }} |
The title you typed |
{{ .Date }}, {{ now }}, {{ now.Format "..." }} |
The current time as an ISO 8601 string |
{{ .File.ContentBaseName }}, {{ .TranslationBaseName }}, {{ .Name }} |
The slug |
{{ replace .File.ContentBaseName "-" " " | title }} (or .TranslationBaseName) |
The title you typed |
After that, comment lines (starting with #) in the frontmatter are dropped, and any other {{ ... }} still in the frontmatter is removed so it can’t break the YAML or TOML parser. The body is left exactly as written, since shortcodes live there and those are supposed to have double braces.
Then Emet parses the result and overrides three keys regardless of what the archetype said: title is what you typed, date is now and draft is true. Everything else in the archetype’s frontmatter is kept, as is the body, and the frontmatter format (YAML or TOML) follows the archetype. So an archetype with draft: false won’t give you published-by-default entries; you’ll have to flip the toggle. That’s deliberate.
A typical archetype:
---
title: "{{ .Title }}"
date: {{ .Date }}
draft: true
tags: []
description: ""
---
Write your content here.The archetype editor#
Archetypes in the sidebar lists the .md files in your archetypes/ directory, default first and the rest alphabetically. Theme archetypes are used when creating entries but aren’t listed here. Click one to open it, use the + button to create one, or the trash icon on a card to delete one (after a confirmation).
The editor is a plain CodeMirror Markdown editor with line wrapping and, if you’ve turned it on in the Markdown editor, Vim mode. There’s no visual mode, because a WYSIWYG editor would make a mess of {{ .Title }}. Save with Ctrl+S, the Save button or :w; Discard reloads the file from the repository. Each save is a commit (Update blog.md).
Creating an archetype asks for a filename (letters, digits, hyphens and underscores; .md is added for you) and starts it off with:
---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
---Name it after the section it’s for, or default to catch everything.
Note that this editor doesn’t do the conflict handling the entry editor does. If the file has changed on the branch since you opened it, your save fails with an error; Discard loads the current version and you can reapply your change.