markdown/frontmatter.go (view raw)
1package markdown
2
3import (
4 "bytes"
5
6 "github.com/adrg/frontmatter"
7)
8
9type Matter map[string]string
10
11type MarkdownDoc struct {
12 Frontmatter Matter
13 Body []byte
14}
15
16func (md *MarkdownDoc) Extract(source []byte) error {
17 r := bytes.NewReader(source)
18 rest, err := frontmatter.Parse(r, &md.Frontmatter)
19 if err != nil {
20 return err
21 }
22 md.Body = rest
23 return nil
24}