pagr

A 'static site generator', built using dati.
Log | Files | Refs | Atom

commit dfc8433ca41bef9f0cf0d29a0a996b762fb250d8
parent 2ad9e0dd634fadd9d2735d8aa22ebf674c64fb41
Author: gearsix <gearsix@tuta.io>
Date:   Sat, 26 Mar 2022 16:14:19 +0000

made DefaultTemplateName an option in the config

Diffstat:
Mconfig.go | 18++++++++++--------
Mpage.go | 4++--
Mpagr.go | 6+++---
Mtemplate.go | 4----
4 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/config.go b/config.go @@ -9,10 +9,11 @@ import ( // Config is the data structure containing all key/values to be loaded // in pagr configuration files type Config struct { - Contents string - Templates string - Assets []string - Output string + Contents string + Templates string + Assets []string + Output string + DefaultTemplate string } // relPaths sets all filepath values in `cfg` relative to `dir` @@ -34,10 +35,11 @@ func (cfg *Config) relPaths(dir string) { // NewConfig returns a Config with default values func NewConfig() Config { return Config{ - Contents: "./content", - Templates: "./templates", - Assets: []string{"./assets"}, - Output: "./out", + Contents: "./content", + Templates: "./templates", + Assets: []string{"./assets"}, + Output: "./out", + DefaultTemplate: "_root", } } diff --git a/page.go b/page.go @@ -89,13 +89,13 @@ func NewPage(path string, updated time.Time) Page { // (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 `DefaultTemplateName` from [./template.go]. -func (p *Page) TemplateName() string { +func (p *Page) TemplateName(defaultName string) string { if v, ok := p.Meta["template"]; ok { return v.(string) } else if v, ok = p.Meta["Template"]; ok { return v.(string) } else { - return DefaultTemplateName + return defaultName } } diff --git a/pagr.go b/pagr.go @@ -107,10 +107,10 @@ func loadConfigFile() Config { } func findPageTemplate(p Page, t []suti.Template) (tmpl suti.Template) { + ptmpl := p.TemplateName(config.DefaultTemplate) for i, template := range t { - if template.Name == p.TemplateName() { - tmpl = t[i] - break + if template.Name == ptmpl { + return t[i] } } return diff --git a/template.go b/template.go @@ -7,10 +7,6 @@ import ( "strings" ) -// DefaultTemplateName provides the default name for the template used -// when one isn't specified in a `Page.Meta`. -const DefaultTemplateName = "_root" - // LoadTemplateDir loads all files in `dir` that are not directories as a `suti.Template` // by calling `suti.LoadTemplateFile`. Partials for each template will be parsed from all // files in a directory matching the base filename of the template (not including