-
Notifications
You must be signed in to change notification settings - Fork 1
/
format.go
58 lines (51 loc) · 1.3 KB
/
format.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package frontmatter
import (
"github.com/BurntSushi/toml"
"gopkg.in/yaml.v3"
)
// DefaultFormats is the list of frontmatter formats
// that are recognized by default.
var DefaultFormats = []Format{TOML, YAML}
// TOML provides support for frontmatter in the TOML format.
// Front matter in this format is expected to be delimited
// by three or more '+' characters.
//
// +++
// title = "Hello, world!"
// tags = ["foo", "bar"]
// +++
var TOML = Format{
Name: "TOML",
Delim: '+',
Unmarshal: toml.Unmarshal,
}
// YAML provides support for frontmatter in the YAML format.
// Front matter in this format is expected to be delimited
// by three or more '-' characters.
//
// ---
// title: Hello, world!
// tags:
// - foo
// - bar
// ---
var YAML = Format{
Name: "YAML",
Delim: '-',
Unmarshal: yaml.Unmarshal,
}
// Format defines a front matter format recognized by this package.
type Format struct {
// Name is a human-readable name for the format.
//
// It may be used in error messages.
Name string
// Delim specifies the delimiter that marks front matter
// in this format.
//
// There must be at least three of these in a row
// for the front matter to be recognized.
Delim byte
// Unmarshal unmarshals the front matter data into the provided value.
Unmarshal func([]byte, any) error
}