frontmatter

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrMissing reports content that does not start with a valid YAML frontmatter block.
	ErrMissing = errors.New("frontmatter: missing YAML frontmatter")
	// ErrUnterminated reports content whose opening delimiter has no matching closing delimiter.
	ErrUnterminated = errors.New("frontmatter: unterminated YAML frontmatter")
	// ErrBOM reports content that starts with a UTF-8 BOM before the YAML frontmatter delimiter.
	ErrBOM = errors.New("frontmatter: UTF-8 BOM before YAML frontmatter")
)

Functions

func Decode

func Decode(content []byte, decode func([]byte) error) (string, error)

Decode splits frontmatter and delegates metadata decoding to the supplied callback.

func Format

func Format[T any](metadata T, body string) (string, error)

Format serializes metadata and a Markdown body using the canonical frontmatter byte shape.

func RewriteStringField

func RewriteStringField(content string, key string, value string) (string, error)

RewriteStringField updates one top-level scalar without reserializing the surrounding document.

func RewriteStringValues

func RewriteStringValues(content []byte, rewrite func(string) string) ([]byte, int, error)

RewriteStringValues changes metadata values while preserving comments, keys, and the Markdown body.

func UnmarshalMetadata

func UnmarshalMetadata(metadata []byte, target any) error

UnmarshalMetadata decodes YAML metadata without exposing the YAML dependency to callers that only need the shared frontmatter parser.

Types

type Parts

type Parts struct {
	Metadata []byte
	Body     string
}

Parts contains the parsed metadata bytes and normalized markdown body.

func Split

func Split(content []byte) (Parts, error)

Split normalizes line endings and separates YAML frontmatter from the body.

Jump to

Keyboard shortcuts

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