feat: render template context

This commit is contained in:
Justin Lin committed 2025-07-25 01:49:29 +10:00
1 parent 99f6e8cefd
commit 437efc6f2e
4 files changed
+59 -39

No files matched your search

+18
View File
@@ -2,6 +2,7 @@ package main
import (
"fmt"
"strings"
"gopkg.in/yaml.v3"
)
@@ -14,3 +15,20 @@ func parseFrontmatter(input string) (meta TemplateMeta, err error) {
}
return
}
func parseDocument(doc string) (frontmatter string, body string, err error) {
doc = strings.TrimLeft(doc, " \n")
sep := "---\n"
if !strings.HasPrefix(doc, sep) {
err = fmt.Errorf("Invalid document: frontmatter required.\n%s", doc)
return
}
parts := strings.Split(doc, sep)
if len(parts) < 3 {
err = fmt.Errorf("Invalid document: frontmatter required.\n%s", doc)
return
}
frontmatter = parts[1]
body = parts[2]
return
}