Documentation
¶
Overview ¶
Package frontmatter provides helpers for parsing and generating YAML frontmatter in markdown documents.
Index ¶
- Constants
- func EditKeys(markdown string, updates []KeyUpdate) (string, error)
- func Generate(values map[string]any, body string) (string, error)
- func GetBool(values map[string]any, key string) bool
- func GetString(values map[string]any, key string) string
- func GetStringSlice(values map[string]any, key string) []string
- func GetTime(values map[string]any, key string) time.Time
- func Parse(markdown string) (map[string]any, string, error)
- func Split(markdown string) (front string, body string, has bool)
- func TopLevelKeyText(markdown, key string) (string, bool)
- type Error
- type ErrorKind
- type KeyBlock
- type KeyUpdate
Constants ¶
const (
// DateLayout matches the KB schema date fields.
DateLayout = "2006-01-02"
)
Variables ¶
This section is empty.
Functions ¶
func EditKeys ¶ added in v0.0.11
EditKeys replaces, deletes or appends only the given top-level keys inside the leading frontmatter of markdown, without re-serializing any other YAML: comments, key order, quoting and indentation of untouched keys are kept byte for byte, and the body is never modified. Each updated key is encoded on its own with the same rules as Generate. New keys are appended at the end of the frontmatter in the order given. `\r\n` line endings are preserved. A document without frontmatter gets a new block (unless every update is a delete). The existing frontmatter must be valid YAML, and the edited result is re-validated before it is returned.
func Generate ¶
Generate encodes frontmatter and prepends it to body. When values is empty, Generate returns body unchanged.
func GetStringSlice ¶
GetStringSlice returns the string slice value for key, or nil when missing.
func Parse ¶
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.
func Split ¶ added in v0.0.11
Split separates the leading frontmatter YAML text (without the delimiter lines) from the body. has is false when markdown has no complete leading frontmatter block (no opening delimiter or no closing delimiter); body is then the whole input.
func TopLevelKeyText ¶ added in v0.0.11
TopLevelKeyText returns the raw text of the top-level key block for key.
Types ¶
type ErrorKind ¶
type ErrorKind string
ErrorKind identifies the failure class for frontmatter operations.