Rename a bunch of internal things from frontmatter to meta
This commit is contained in:
parent
37022e051a
commit
b14d92205c
22
meta.go
22
meta.go
@ -2,7 +2,7 @@ package step
|
||||
|
||||
import "strings"
|
||||
|
||||
const frontMatterRule = "---"
|
||||
const metaRule = "---"
|
||||
|
||||
// Meta represents optional metadata that can occur at the very start of
|
||||
// a document.
|
||||
@ -18,25 +18,25 @@ func SplitMeta (input string) (Meta, string, error) {
|
||||
// by line instead of operating directly on the string. have that call
|
||||
// yet another function which will solve #11
|
||||
|
||||
// stop if there is no front matter
|
||||
if !strings.HasPrefix(input, frontMatterRule + "\n") {
|
||||
// stop if there is no metadata
|
||||
if !strings.HasPrefix(input, metaRule + "\n") {
|
||||
return Meta { }, input, nil
|
||||
}
|
||||
|
||||
// get the start and the end of the front matter
|
||||
input = strings.TrimPrefix(input, frontMatterRule)
|
||||
index := strings.Index(input, "\n" + frontMatterRule + "\n")
|
||||
// get the start and the end of the metadata
|
||||
input = strings.TrimPrefix(input, metaRule)
|
||||
index := strings.Index(input, "\n" + metaRule + "\n")
|
||||
if index < 0 {
|
||||
return nil, "", ErrMetaNeverClosed
|
||||
}
|
||||
frontMatterRaw := input[:index]
|
||||
body := input[index + len(frontMatterRule) + 2:]
|
||||
metaStr := input[:index]
|
||||
bodyStr := input[index + len(metaRule) + 2:]
|
||||
|
||||
// parse meta
|
||||
meta, err := ParseMeta(frontMatterRaw)
|
||||
// parse metadata
|
||||
meta, err := ParseMeta(metaStr)
|
||||
if err != nil { return Meta { }, "", err }
|
||||
|
||||
return meta, body, nil
|
||||
return meta, bodyStr, nil
|
||||
}
|
||||
|
||||
// ParseMeta parses isolated metadata (without the horizontal starting and
|
||||
|
Loading…
Reference in New Issue
Block a user