fixed yaml frontmatter not being parsed properly
This commit is contained in:
parent
46f7891e1b
commit
b30e0d3ed9
1 changed files with 4 additions and 2 deletions
|
@ -30,12 +30,14 @@ type Metadata map[string]interface{}
|
||||||
|
|
||||||
func processWithYaml(f []byte) (Metadata, []byte, error) {
|
func processWithYaml(f []byte) (Metadata, []byte, error) {
|
||||||
// Check if the file has valid metadata
|
// Check if the file has valid metadata
|
||||||
if !bytes.HasPrefix(f, []byte("---\n")) {
|
trimmed := bytes.TrimSpace(f)
|
||||||
|
normalized := strings.ReplaceAll(string(trimmed), "\r\n", "\n")
|
||||||
|
if !strings.HasPrefix(normalized, ("---\n")) {
|
||||||
// No valid yaml, so return the entire content
|
// No valid yaml, so return the entire content
|
||||||
return nil, f, nil
|
return nil, f, nil
|
||||||
}
|
}
|
||||||
// Separate YAML from rest of document
|
// Separate YAML from rest of document
|
||||||
split := strings.SplitN(string(f), "---\n", 3)
|
split := strings.SplitN(normalized, "---\n", 3)
|
||||||
if len(split) < 3 {
|
if len(split) < 3 {
|
||||||
return nil, nil, fmt.Errorf("Invalid frontmatter format.")
|
return nil, nil, fmt.Errorf("Invalid frontmatter format.")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue