commit 70edff1f870461aede1fc1e972bc5f19019e4330
parent e814e9482dda7d821dfd7439eebac4bc00b629a1
Author: gearsix <gearsix@tuta.io>
Date: Tue, 6 Jul 2021 12:35:24 +0100
formatting; added DefaultTemplate & Page.GetTemplate()
Diffstat:
2 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/content.go b/content.go
@@ -114,18 +114,32 @@ func (m Meta) MergeMeta(meta Meta, overwrite bool) {
}
type Page struct {
- Path string
- Meta Meta
- Contents []string
- Assets []string
+ Path string
+ Meta Meta
+ Contents []string
+ Assets []string
}
func NewPage(path string) Page {
return Page{
- Path: path,
- Meta: make(Meta),
- Contents: make([]string, 0),
- Assets: make([]string, 0),
+ Path: path,
+ Meta: make(Meta),
+ Contents: make([]string, 0),
+ Assets: make([]string, 0),
+ }
+}
+
+// GetTemplate will check if `p.Meta` has the key `template` or `Template`
+// (in the order) and return the value of the first existing key as a string.
+// If `.Meta` neither has the key `template` or `Template`, then it will
+// return `DefaultTemplate` from [./template.go].
+func (p *Page) GetTemplate() string {
+ if v, ok := p.Meta["template"]; ok {
+ return v.(string)
+ } else if v, ok = p.Meta["Template"]; ok {
+ return v.(string)
+ } else {
+ return DefaultTemplate
}
}
diff --git a/template.go b/template.go
@@ -8,6 +8,8 @@ import (
"notabug.org/gearsix/suti"
)
+const DefaultTemplate = "root"
+
func loadPaths(dir string) ([]string, error) {
var r []string
err := filepath.Walk(dir,