templates.go: Support default base templates

If a base template is not found in the current directory, look for a
default base template at templates/_default/base.ext.

Also prevent partial templates from inheriting from base templates.
This commit is contained in:
Edd Salkield 2022-09-25 18:03:39 +01:00 committed by Adnan Maolood
parent 299cb5e1d1
commit ade84c9358

View file

@ -148,11 +148,19 @@ func (t *Templates) Load(dir string, exts []string) error {
if _, ok := extsMap[ext]; !ok {
continue
}
if strings.HasPrefix(path, "_partials/") {
continue
}
basePath := pathpkg.Join(pathpkg.Dir(path), "base"+ext)
if path == basePath {
continue
}
if base, ok := t.tmpls[basePath]; ok {
base, ok := t.tmpls[basePath]
if !ok {
basePath = pathpkg.Join("_default", "base"+ext)
base, ok = t.tmpls[basePath]
}
if ok {
tmpl, err := base.Clone()
if err != nil {
return err