Templates

Templates are HTML files stored in the templates/ directory. Hunim wraps Markdown content inside the matching template before writing it to public/.

Default template

Create templates/default.html and it will be applied to every Markdown file that does not specify a custom template:

<!DOCTYPE html>
<html lang="{{ .Lang }}">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{{ .Title }}</title>
  {{ .MetaTags }}
  <link rel="stylesheet" href="/style.css">{{ .Reload }}
</head>
<body>
  {{ .Content }}
</body>
</html>

Template variables

VariableDescription
{{ .Content }}The rendered HTML from the Markdown file.
{{ .Title }}The title field from frontmatter.
{{ .Date }}The formatted date (e.g. November 19, 2024). Only set for feed posts.
{{ .Author }}The author field from frontmatter. Only set for feed posts.
{{ .Lang }}The languageCode from hunim.toml.
{{ .MetaTags }}Generated <meta> tags for SEO (og:title, description, canonical URL).
{{ .Reload }}Dev-server auto-reload script. Injected when running hunim server; empty in production.

Custom templates

A page can use a specific template by setting template in its frontmatter:

---
title: About
template: wide.html
---

Hunim will look for templates/wide.html instead of templates/default.html.

Feed templates

Directories marked as feeds automatically look for a template named {dirname}_list.html. For a feed in src/blog/, create templates/blog_list.html to style individual blog posts. See Feeds for details.

Components in templates

Templates can include components using the component name syntax:

<body>
  {{ nav }}
  <main>
    {{ .Content }}
  </main>
  {{ footer }}
</body>

Placement of Reload

Place &#123;&#123; .Reload &#125;&#125; just before the closing </head> tag (or at the end of <body>). It injects a small polling script only when the dev server is active — in production builds the tag is replaced with nothing.