1
0
mirror of https://git.sr.ht/~adnano/kiln synced 2024-09-19 01:31:36 +02:00
kiln/frontmatter.go

24 lines
446 B
Go
Raw Normal View History

2021-04-21 21:13:45 +02:00
package main
import "bytes"
var (
frontmatterOpen = []byte("---")
frontmatterClose = []byte("\n---")
)
func extractFrontmatter(b []byte) (frontmatter, content []byte) {
if !bytes.HasPrefix(b, frontmatterOpen) {
return nil, b
}
fm := b[len(frontmatterOpen):]
if len(fm) != 0 && fm[0] != '\n' {
return nil, b
}
i := bytes.Index(fm, frontmatterClose)
if i == -1 {
i = len(fm)
}
return fm[:i], b[len(frontmatterOpen)+len(fm):]
}