class

Hwaro::Services::FrontmatterConverter

Inherits Reference / Object

Frontmatter Converter converts between YAML and TOML formats

Constants

TOML_DELIMITER = "+++"
TOML_FRONTMATTER_RE = /\A\+\+\+\s*\n(.*?\n?)^\+\+\+[ \t]*(?:\r?\n|\z)(.*)\z/m
YAML_DELIMITER = "---"
YAML_FRONTMATTER_RE = /\A---\s*\n(.*?\n?)^---[ \t]*(?:\r?\n|\z)(.*)\z/m

Frontmatter splitters. The closing-delimiter clause matches trailing horizontal whitespace and exactly one newline (or end of file) — not \s*$\n?, which would silently swallow a blank line between the delimiter and the body. The body capture keeps any blank line as a leading \n, so round-tripping TOML↔YAML preserves the author's original spacing (regression: blank line was lost).

Constructors

new(content_dir : String = "content")
Source

Class methods

serialize_time(time : Time) : String

Serialize a frontmatter date/time value without corrupting the calendar day.

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, silently shifting the post's date on a format round-trip. When the value carries no time-of-day we emit a bare YYYY-MM-DD date and keep the day; genuine timestamps round-trip as RFC 3339.

Source

Instance methods

convert_file(file_path : String, target_format : FrontmatterFormat) : Bool

Convert a single file's frontmatter

Source
convert_to_json

Convert all content files to JSON format

Source
convert_to_toml

Convert all content files to TOML format

Source
convert_to_yaml

Convert all content files to YAML format

Source
detect_format(content : String) : FrontmatterFormat

Detect the frontmatter format of a file

Source