Documentation
¶
Overview ¶
Package email provides frontmatter parsing and serialization using email-style headers (RFC 822-inspired key: value pairs).
This format is unusual among SSGs but offers a few advantages: it is human-writable without indentation rules, supports comments via lines starting with '#', and requires no external dependencies.
Example frontmatter:
Title: My Post Date: 2024-01-15 Tags: go, ssg, web # this is a comment <body content starts after the blank line>
Index ¶
- Variables
- func ApplyTransforms(k string, v any, tx []ValueTransformer) (any, error)
- func Marshal(data map[string]any) ([]byte, error)
- func NewLoader(tx ...ValueTransformer) func([]byte) (map[string]any, []byte, error)
- func Set(kv map[string]any, k string, v any, tx []ValueTransformer) error
- func Unmarshal(src []byte, out map[string]any, tx ...ValueTransformer) error
- type ValueTransformer
Constants ¶
This section is empty.
Variables ¶
var Loader = NewLoader()
Loader is the default MetaLoader for email-style frontmatter with no value transformers. Use NewLoader to apply transformers such as AsList.
Functions ¶
func ApplyTransforms ¶
func ApplyTransforms(k string, v any, tx []ValueTransformer) (any, error)
ApplyTransforms runs tx in order against (k, v). If any transformer returns io.EOF, that value is used and iteration stops.
func Marshal ¶
Marshal serializes a map[string]any into email-header style output. Nested maps are written with dotted key prefixes (e.g. "author.name: foo").
func NewLoader ¶
NewLoader returns a MetaLoader for email-style frontmatter, applying tx in order to each parsed key/value pair.
email.NewLoader(email.AsList("Tags"))
Types ¶
type ValueTransformer ¶
ValueTransformer is a function that can inspect or transform a parsed key/value pair. Return io.EOF to signal the value has been fully handled and no further transformers should run.
func AsList ¶
func AsList(key string) ValueTransformer
AsList returns a ValueTransformer that parses the named key's value as a CSV list rather than a plain string.