frontmatter

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package frontmatter reads and edits the YAML frontmatter of a markdown note.

Edits are line-based: setting or deleting a key rewrites only that key's lines. Every other byte of the file (comments, key order, blank lines, quoting style, line endings and the body) is left exactly as it was. Values are parsed and encoded with goccy/go-yaml.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(src []byte, key string) []byte

Delete returns src without key. Deleting a missing key returns src as is.

func Set

func Set(src []byte, key string, value any) ([]byte, error)

Set returns src with key set to value. Only the key's own lines change; a missing key is appended at the end of the block, and a note without frontmatter gets a new block.

func SetLiteral

func SetLiteral(src []byte, key, literal string) ([]byte, error)

SetLiteral is Set for a value already formatted as YAML, written as it is: no quoting. Use it to keep a line's style, e.g. an RFC 3339 timestamp that was written without quotes.

Types

type Doc

type Doc struct {
	// contains filtered or unexported fields
}

Doc is a note split into its frontmatter and body.

func Split

func Split(src []byte) Doc

Split parses src into a Doc. A note has frontmatter only when its first line is "---" and a later line is "---" or "...", as in Obsidian.

func (Doc) Body

func (d Doc) Body() []byte

Body returns everything after the frontmatter block.

func (Doc) Front

func (d Doc) Front() []byte

Front returns the raw YAML between the delimiters.

func (Doc) Has

func (d Doc) Has() bool

Has reports whether the note has a frontmatter block.

func (Doc) Properties

func (d Doc) Properties() (map[string]any, error)

Properties decodes the frontmatter into a map. A note without frontmatter has no properties.

Jump to

Keyboard shortcuts

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