YAML module

The YAML module provides two features:

  1. A data loader for .yml and .yaml files in /.lunet/data/
  2. A front matter parser for ----delimited YAML front matter in content pages

It depends on the Datas module and uses the SharpYaml library with the extended schema.

YAML front matter

Pages can include YAML front matter delimited by ---:

---
title: "Hello"
tags: ["docs", "guide"]
date: 2024-01-15
---

# Hello
This is content.

Front matter must start with an explicit --- delimiter. All key-value pairs become page-level template variables accessible in layouts and includes.

YAML data files

Place data files under /.lunet/data/:

# /.lunet/data/project.yml
name: Lunet
version: "1.0"

Access it in templates:

site.data.project.name

Type conversion

YAML scalar values are automatically typed using SharpYaml's extended schema:

YAML value Scriban type Examples
Mapping ScriptObject key: value
Sequence ScriptArray [a, b, c] or - item
Integer int or long 42, 0xFF
Float double 3.14, .inf
Boolean bool true, false, yes, no
Null null null, ~
Timestamp DateTime 2024-01-15
String string "hello", unquoted text

Multi-document YAML

Data files with multiple ----separated documents produce a ScriptArray of top-level objects:

---
name: "First"
---
name: "Second"

This becomes a ScriptArray with two ScriptObject elements.

Edge cases

  • Front matter must begin with explicit --- — files without this delimiter are treated as having no front matter.
  • Duplicate keys in a YAML mapping cause an error.
  • Front matter values can be overwritten by later script execution (they are not read-only).

See also