page.go: report error in template override failure

Raise an error when users specify a template in frontmatter which cannot
be resolved.
This commit is contained in:
Edd Salkield 2022-10-04 15:22:51 +01:00 committed by adnano
parent 81e35cb1eb
commit 505244bea2

View file

@ -199,6 +199,9 @@ func (p *Page) process(cfg *Site, task *Task) error {
tmplName = "index"
}
tmpl, ok := cfg.templates.FindTemplate(p.FilePath, tmplName+task.TemplateExt)
if !ok && p.Template != "" {
return fmt.Errorf("failed to generate index page %q: template %q specified in frontmatter but not found", p.Path, tmplName)
}
if ok {
var b strings.Builder
if err := tmpl.Execute(&b, p); err != nil {
@ -216,6 +219,9 @@ func (p *Page) process(cfg *Site, task *Task) error {
}
var b strings.Builder
tmpl, ok := cfg.templates.FindTemplate(p.FilePath, tmplName+task.TemplateExt)
if !ok && p.Pages[i].Template != "" {
return fmt.Errorf("failed to generate page %q: template %q specified in frontmatter but not found", p.Pages[i].Path, tmplName)
}
if ok {
if err := tmpl.Execute(&b, p.Pages[i]); err != nil {
return err