mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-10-30 01:13:08 +00:00
24 lines
446 B
Go
24 lines
446 B
Go
|
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):]
|
||
|
}
|