mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-12-04 19:08:22 +01:00
25 lines
475 B
Go
25 lines
475 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
|
|
}
|
|
if len(b) > len(frontmatterOpen) && b[len(frontmatterOpen)] != '\n' {
|
|
return nil, b
|
|
}
|
|
b = b[len(frontmatterOpen):]
|
|
|
|
i := bytes.Index(b, frontmatterClose)
|
|
if i == -1 {
|
|
return b, nil
|
|
}
|
|
return b[:i], b[i+len(frontmatterClose):]
|
|
}
|