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"
|
import "strings"
|
||||||
|
|
||||||
const frontMatterRule = "---"
|
const metaRule = "---"
|
||||||
|
|
||||||
// Meta represents optional metadata that can occur at the very start of
|
// Meta represents optional metadata that can occur at the very start of
|
||||||
// a document.
|
// 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
|
// by line instead of operating directly on the string. have that call
|
||||||
// yet another function which will solve #11
|
// yet another function which will solve #11
|
||||||
|
|
||||||
// stop if there is no front matter
|
// stop if there is no metadata
|
||||||
if !strings.HasPrefix(input, frontMatterRule + "\n") {
|
if !strings.HasPrefix(input, metaRule + "\n") {
|
||||||
return Meta { }, input, nil
|
return Meta { }, input, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the start and the end of the front matter
|
// get the start and the end of the metadata
|
||||||
input = strings.TrimPrefix(input, frontMatterRule)
|
input = strings.TrimPrefix(input, metaRule)
|
||||||
index := strings.Index(input, "\n" + frontMatterRule + "\n")
|
index := strings.Index(input, "\n" + metaRule + "\n")
|
||||||
if index < 0 {
|
if index < 0 {
|
||||||
return nil, "", ErrMetaNeverClosed
|
return nil, "", ErrMetaNeverClosed
|
||||||
}
|
}
|
||||||
frontMatterRaw := input[:index]
|
metaStr := input[:index]
|
||||||
body := input[index + len(frontMatterRule) + 2:]
|
bodyStr := input[index + len(metaRule) + 2:]
|
||||||
|
|
||||||
// parse meta
|
// parse metadata
|
||||||
meta, err := ParseMeta(frontMatterRaw)
|
meta, err := ParseMeta(metaStr)
|
||||||
if err != nil { return Meta { }, "", err }
|
if err != nil { return Meta { }, "", err }
|
||||||
|
|
||||||
return meta, body, nil
|
return meta, bodyStr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseMeta parses isolated metadata (without the horizontal starting and
|
// ParseMeta parses isolated metadata (without the horizontal starting and
|
||||||
|
Loading…
Reference in New Issue
Block a user