frontmatter

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package frontmatter provides helpers for parsing and generating YAML frontmatter in markdown documents.

Index

Constants

View Source
const (
	// DateLayout matches the KB schema date fields.
	DateLayout = "2006-01-02"
)

Variables

This section is empty.

Functions

func Generate

func Generate(values map[string]any, body string) (string, error)

Generate encodes frontmatter and prepends it to body. When values is empty, Generate returns body unchanged.

func GetBool

func GetBool(values map[string]any, key string) bool

GetBool returns the bool value for key, or false when missing.

func GetString

func GetString(values map[string]any, key string) string

GetString returns the string value for key, or the zero value when missing.

func GetStringSlice

func GetStringSlice(values map[string]any, key string) []string

GetStringSlice returns the string slice value for key, or nil when missing.

func GetTime

func GetTime(values map[string]any, key string) time.Time

GetTime returns the time value for key, or the zero time when missing.

func Parse

func Parse(markdown string) (map[string]any, string, error)

Parse extracts YAML frontmatter from markdown content and returns the decoded metadata plus the remaining markdown body. When the markdown has no leading frontmatter block, Parse returns an empty map and the original body.

Types

type Error

type Error struct {
	Kind ErrorKind
	Key  string
	Line int
	Err  error
}

Error reports structured parse and generation failures.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the wrapped error.

type ErrorKind

type ErrorKind string

ErrorKind identifies the failure class for frontmatter operations.

const (
	ErrorKindMissingClosingDelimiter ErrorKind = "missing_closing_delimiter"
	ErrorKindInvalidYAML             ErrorKind = "invalid_yaml"
	ErrorKindUnsupportedValue        ErrorKind = "unsupported_value"
)

Jump to

Keyboard shortcuts

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