mirror of
https://git.sr.ht/~adnano/kiln
synced 2024-11-08 14:19:20 +01:00
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:
parent
0a2e7b6fd0
commit
63b63a32e1
10
templates.go
10
templates.go
@ -148,11 +148,19 @@ func (t *Templates) Load(dir string, exts []string) error {
|
|||||||
if _, ok := extsMap[ext]; !ok {
|
if _, ok := extsMap[ext]; !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(path, "_partials/") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
basePath := pathpkg.Join(pathpkg.Dir(path), "base"+ext)
|
basePath := pathpkg.Join(pathpkg.Dir(path), "base"+ext)
|
||||||
if path == basePath {
|
if path == basePath {
|
||||||
continue
|
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()
|
tmpl, err := base.Clone()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user