frontmatter

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package frontmatter reads and parses the YAML frontmatter block from spec nodes, test nodes, and external dependency files.

Frontmatter is the YAML content between the first "---" and the second "---" at the top of the file. Everything after the closing "---" is ignored.

This package only extracts the fields relevant to the code-from-spec toolchain (depends_on, implements). All other YAML fields are silently ignored. Validation of required fields is the caller's responsibility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DependsOn

type DependsOn struct {
	// LogicalName is the "path" field in the YAML — the dependency's logical
	// name as defined by the Code from Spec framework.
	LogicalName string `yaml:"path"`

	// Filter is an optional list of glob patterns (relative to the external
	// dependency folder). When non-empty, only files matching at least one
	// pattern are imported (plus _external.md, which is always included).
	Filter []string `yaml:"filter"`
}

DependsOn represents a single entry in the depends_on list of a spec node.

LogicalName is the logical name of the dependency (e.g. "EXTERNAL/database" or "ROOT/payments/fees"). Filter is an optional set of glob patterns used to select a subset of files within an external dependency folder; it applies only to EXTERNAL/ dependencies and is ignored otherwise.

type Frontmatter

type Frontmatter struct {
	// DependsOn lists all cross-tree dependencies declared by this node.
	DependsOn []DependsOn `yaml:"depends_on"`

	// Implements lists the source files generated by this node.
	// Paths are relative to the project root.
	Implements []string `yaml:"implements"`
}

Frontmatter holds the fields extracted from a spec node's YAML frontmatter. All fields are optional at the parsing level — validation happens elsewhere.

func ParseFrontmatter

func ParseFrontmatter(filePath string) (*Frontmatter, error)

ParseFrontmatter reads the file at filePath, extracts the YAML frontmatter block (between the first "---" line and the second "---" line), and returns the parsed result.

The parser reads the file line by line and stops as soon as the closing "---" is found — the file body is never read into memory, keeping this efficient even for large spec files.

Caching is the caller's responsibility; this function always reads from disk.

Errors returned:

"error reading <path>: <underlying error>"
"error parsing frontmatter in <path>: <underlying error>"
"frontmatter not found in <path>"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL