summaryrefslogtreecommitdiff
path: root/internal/frontmatter
diff refs
from: back
to: back
| flip
diff options
context:
space:
mode:
Diffstat (limited to 'internal/frontmatter')
-rw-r--r--internal/frontmatter/parser.go33
1 files changed, 18 insertions, 15 deletions
diff --git a/internal/frontmatter/parser.go b/internal/frontmatter/parser.go
index 83312dc..942760c 100644
--- a/internal/frontmatter/parser.go
+++ b/internal/frontmatter/parser.go
@@ -1,35 +1,38 @@
package frontmatter
import (
+ "bytes"
"fmt"
- "regexp"
"time"
"gopkg.in/yaml.v3"
)
type Metadata struct {
- Title string `yaml:"title"`
- ShortDescription string `yaml:"shortDescription"`
- ActionDate string `yaml:"actionDate"`
- PublishedTime time.Time `yaml:"publishedTime"`
- Thumbnail string `yaml:"thumbnail"`
- Tags []string `yaml:"tags"`
- Geolocation string `yaml:"geolocation"`
- Medley string `yaml:"medley"`
- MedleyPart int `yaml:"medleyPart"`
+ Title string `yaml:"title"`
+ ShortDescription string `yaml:"shortDescription"`
+ ActionDate string `yaml:"actionDate"`
+ PublishedTime time.Time `yaml:"publishedTime"`
+ Thumbnail string `yaml:"thumbnail"`
+ Tags []string `yaml:"tags"`
+ Geolocation string `yaml:"geolocation"`
+ Medley string `yaml:"medley"`
+ MedleyPart int `yaml:"medleyPart"`
+ ContentSettings map[string]string `yaml:"contentSettings"`
}
func ParseFrontmatter(content []byte) (metadata *Metadata, markdown []byte, err error) {
- frontmatterRegex := regexp.MustCompile(`^---\s*\r?\n([\s\S]*?)\r?\n---\s*\r?\n([\s\S]*)$`)
- matches := frontmatterRegex.FindSubmatch(content)
+ if !bytes.HasPrefix(content, []byte("---\n")) {
+ return nil, content, nil
+ }
- if len(matches) != 3 {
+ end := bytes.Index(content[4:], []byte("\n---\n"))
+ if end == -1 {
return nil, content, nil
}
- yamlContent := matches[1]
- markdownContent := matches[2]
+ yamlContent := content[4 : end+4]
+ markdownContent := content[end+9:]
metadata = &Metadata{}
if err := yaml.Unmarshal([]byte(yamlContent), &metadata); err != nil {