page: Fallback to base template for page/index templates

Implements: https://todo.sr.ht/~adnano/kiln/22
This commit is contained in:
adnano 2022-02-09 00:39:48 -05:00
parent fb6470aa5f
commit d6f8c03ec3

View file

@ -169,6 +169,10 @@ func (p *Page) process(cfg *Site, task *Task) error {
// Create index // Create index
if p.index { if p.index {
tmpl, ok := cfg.templates.FindTemplate(p.Path, "index"+task.TemplateExt) tmpl, ok := cfg.templates.FindTemplate(p.Path, "index"+task.TemplateExt)
if !ok {
// Try the base template
tmpl, ok = cfg.templates.FindTemplate(p.Path, "base"+task.TemplateExt)
}
if ok { if ok {
var b strings.Builder var b strings.Builder
if err := tmpl.Execute(&b, p); err != nil { if err := tmpl.Execute(&b, p); err != nil {
@ -182,6 +186,10 @@ func (p *Page) process(cfg *Site, task *Task) error {
for i := range p.Pages { for i := range p.Pages {
var b strings.Builder var b strings.Builder
tmpl, ok := cfg.templates.FindTemplate(p.Path, "page"+task.TemplateExt) tmpl, ok := cfg.templates.FindTemplate(p.Path, "page"+task.TemplateExt)
if !ok {
// Try the base template
tmpl, ok = cfg.templates.FindTemplate(p.Path, "base"+task.TemplateExt)
}
if ok { if ok {
if err := tmpl.Execute(&b, p.Pages[i]); err != nil { if err := tmpl.Execute(&b, p.Pages[i]); err != nil {
return err return err