module

Hwaro::Utils::FrontmatterWriter

Constants

YAML_RESERVED_WORDS = ["true", "false", "yes", "no", "on", "off", "null", "none", "y", "n", "~"] of ::String

YAML 1.1 words that reparse as booleans/null when left bare (Jekyll runs on Psych). y/n included defensively.

Class methods

escape_toml_string(str : String) : String

Escape a string for a double-quoted TOML basic string. Unlike Crystal's String#inspect, this never emits TOML-invalid escapes (\a, \e, \v) and leaves non-ASCII text raw (\u is exactly four digits — ext/toml_unicode_escape_fix.cr — so a following hex digit is literal).

Source
format_toml_key(key : String) : String

Quote a frontmatter key that isn't a bare TOML key (spaces, dots, non-ASCII — all valid in YAML/JSON source).

Source
serialize_time(time : Time) : String

Serialize a frontmatter date/time value without corrupting the calendar day or the author's zone.

Frontmatter dates are commonly written as TOML/YAML local dates such as 2026-05-20, which parse to midnight in the local time zone. Rendering those through to_rfc3339 (always UTC) rolls the day back in any positive-offset zone — e.g. in KST 2026-05-20 becomes 2026-05-19T15:00:00Z. When the value carries no time-of-day we emit a bare YYYY-MM-DD; genuine timestamps keep their own offset (to_rfc3339 would silently convert 08:00+09:00 to the previous day's 23:00Z).

The bare-date shortcut applies only to a UTC or LOCAL-ZONE midnight — the shapes a parsed bare date actually takes (local midnight; YAML gave UTC midnight before ext/yaml_local_time_fix) — so authored bare dates round-trip unchanged through their own format. Note the UTC branch is deliberately lossy for an authored ...T00:00:00Z timestamp when the file is later reparsed as TOML (local zone); that trade-off keeps YAML bare dates stable and predates this rule. A midnight with any other fixed offset is a genuine timestamp: collapsing it to YYYY-MM-DD silently shifted the instant, so it keeps its offset. Fractional seconds are preserved in both timestamp forms.

Any other local-zone value is a zone-less date-time as authored (2024-01-02T03:04:05, which TOML and YAML both parse in the local zone), so it is written without an offset rather than pinning the converting machine's zone. On a UTC machine it can't be told from an authored Z, so it stays Z there.

Source
toml_to_yaml_any(value : TOML::Any, depth : Int32 = 0) : YAML::Any

Convert a parsed TOML value into the YAML::Any tree the emitters consume. Time leaves become frontmatter date strings (see serialize_time).

Source
yaml_scalar(str : String) : String

Render a string as a YAML flow scalar, leaving simple values bare and double-quoting anything YAML would reinterpret — beta: gamma parses as a mapping, NO as false, 2024-01-15 as a date, *x as an alias.

Source

Nested types