frontmatter

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package frontmatter parses YAML frontmatter blocks from markdown files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Strip

func Strip(content string) (string, error)

Strip is upstream's stripFrontmatter (utils/frontmatter.ts:40): the body of content without its frontmatter. Malformed YAML in the header is an error, as upstream's parse throws.

Types

type Doc

type Doc struct {
	// Frontmatter holds the YAML values from the document header.
	Frontmatter map[string]any
	// Value is what Pi's parseFrontmatter returns as `frontmatter`: the parsed header (`parsed ?? {}`), which is a mapping, or an array, string, number or boolean when the header is not a mapping. Frontmatter is the mapping, or empty.
	Value any
	// Body is the trimmed markdown content following the closing `---`.
	Body string
	// Err reports malformed YAML. The body remains available to callers that
	// intentionally tolerate malformed frontmatter.
	Err error
}

Doc is a parsed markdown-with-frontmatter file.

func Parse

func Parse(content string) Doc

Parse extracts and parses a YAML frontmatter block plus body. If the file does not begin with a closed frontmatter block, the whole input is returned as Body and Frontmatter is empty.

func ParseOrdered

func ParseOrdered(content string) Doc

ParseOrdered is Parse with Value built by yaml12.ParseOrdered: each object in it is a *yaml12.Object that lists its keys in insertion order, which is the order a JavaScript object enumerates them in (after its array-index keys). Frontmatter is the top-level mapping's map as in Parse.

func (Doc) Bool

func (d Doc) Bool(key string) bool

Bool returns the named field as a bool, defaulting to false.

func (Doc) String

func (d Doc) String(key string) string

String returns the named field as a string, or "" if missing.

Jump to

Keyboard shortcuts

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