Blog

0002: Use YAML Front Matter

Context

We are planning to use Hugo as SSG for this project and host it’s source code on GitHub.

We would like to make ADR archetype to manage ADRs through hugo new content adrs/NNNN-title.md. Hugo provides these available formats for front matter:

We want to select a front matter format that would work well with both GitHub and Hugo.

[!NOTE] YAML frontmatter values are only for GitHub Docs, not for regular frontmatter rendering

Decision

Use YAML metadata because GitHub does not support TOML and JSON

The reason is GitHub’s support for YAML front matter. If they would support TOML front matter, we would change. But they don’t.1

Alternatives

JSON

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.2

Verdict: Not acceptable. JSON is too verbose for front matter usage, and GitHub does not support it for front matter usage.

TOML

TOML aims to be a minimal configuration file format that’s easy to read due to obvious semantics. TOML is designed to map unambiguously to a hash table. TOML should be easy to parse into data structures in a wide variety of languages.3

Verdict: Not acceptable. TOML is too verbose when writing deep heirachical data, but this is should not be a big issue for front matter. The main one that GitHub does not support it for front matter usage.

Consequences

Pros:

Cons:

Resources


  1. Comment on “consistency: hugo new site uses config.toml, but YAML for content”, B. E. Pedersen (bep), 2018-09-21 ↩︎

  2. JSON description ↩︎

  3. TOML description ↩︎

  4. How Hugo determines front matter ↩︎