Components

Components are reusable HTML snippets stored in the components/ directory. They can be embedded in templates, HTML source files, and Markdown files alike.

Basic usage

Create a component file, for example components/header.html:

<header>
  <a href="/">Home</a>
  <a href="/blog/">Blog</a>
  <a href="/about">About</a>
</header>

Then reference it anywhere with the component name (without the .html extension):

{{ header }}

Hunim replaces the tag with the file's contents at build time. A component named nav would live in components/nav.html and be referenced as &#123;&#123; nav &#125;&#125;.

Components with parameters

Components accept positional string arguments. Inside the component file, reference them as {{ $1 }}, {{ $2 }}, etc.

components/button.html:

<a href="{{ $1 }}" class="btn">{{ $2 }}</a>

Usage:

{{ button "/getting-started" "Read the docs" }}

Output:

<a href="/getting-started" class="btn">Read the docs</a>

NimScript execution

Files ending in .nims in the components/ directory can be run at build time. Their standard output replaces the tag in the page.

components/build_time.nims:

import times
echo now().format("yyyy-MM-dd")

Invoke a script using the exec tag (double curly braces around exec scriptname.nims):

{{ exec build_time.nims }}

This embeds the current build date into the page. Any .nims file in components/ can be executed this way.

Requirements

NimScript gives you access to Nim's standard library, so you can read files, call httpclient, or generate any HTML dynamically at build time.

Caching

All components are loaded into memory at startup and reused for each file. There is no per-page filesystem read — the cache is invalidated when the server detects a change and triggers a rebuild.