summaryrefslogtreecommitdiffstats
path: root/hugolib/site_render.go
diff options
context:
space:
mode:
Diffstat (limited to 'hugolib/site_render.go')
-rw-r--r--hugolib/site_render.go64
1 files changed, 47 insertions, 17 deletions
diff --git a/hugolib/site_render.go b/hugolib/site_render.go
index 34f288da2..a55cbb402 100644
--- a/hugolib/site_render.go
+++ b/hugolib/site_render.go
@@ -19,6 +19,8 @@ import (
"strings"
"sync"
+ "github.com/gohugoio/hugo/tpl"
+
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/output"
@@ -136,33 +138,62 @@ func pageRenderer(
continue
}
- layouts, err := p.getLayouts()
+ templ, found, err := p.resolveTemplate()
if err != nil {
- s.Log.ERROR.Printf("Failed to resolve layout for output %q for page %q: %s", f.Name, p, err)
+ s.SendError(p.errorf(err, "failed to resolve template"))
continue
}
- targetPath := p.targetPaths().TargetFilename
-
- if targetPath == "" {
- s.Log.ERROR.Printf("Failed to create target path for output %q for page %q: %s", f.Name, p, err)
+ if !found {
+ s.logMissingLayout("", p.Kind(), f.Name)
continue
}
- if err := s.renderAndWritePage(&s.PathSpec.ProcessingStats.Pages, "page "+p.Title(), targetPath, p, layouts...); err != nil {
+ targetPath := p.targetPaths().TargetFilename
+
+ if err := s.renderAndWritePage(&s.PathSpec.ProcessingStats.Pages, "page "+p.Title(), targetPath, p, templ); err != nil {
results <- err
}
if p.paginator != nil && p.paginator.current != nil {
- if err := s.renderPaginator(p, layouts); err != nil {
+ if err := s.renderPaginator(p, templ); err != nil {
results <- err
}
}
}
}
+func (s *Site) logMissingLayout(name, kind, outputFormat string) {
+ log := s.Log.WARN
+ if name != "" && infoOnMissingLayout[name] {
+ log = s.Log.INFO
+ }
+
+ errMsg := "You should create a template file which matches Hugo Layouts Lookup Rules for this combination."
+ var args []interface{}
+ msg := "found no layout file for"
+ if outputFormat != "" {
+ msg += " %q"
+ args = append(args, outputFormat)
+ }
+
+ if kind != "" {
+ msg += " for kind %q"
+ args = append(args, kind)
+ }
+
+ if name != "" {
+ msg += " for %q"
+ args = append(args, name)
+ }
+
+ msg += ": " + errMsg
+
+ log.Printf(msg, args...)
+}
+
// renderPaginator must be run after the owning Page has been rendered.
-func (s *Site) renderPaginator(p *pageState, layouts []string) error {
+func (s *Site) renderPaginator(p *pageState, templ tpl.Template) error {
paginatePath := s.Cfg.GetString("paginatePath")
@@ -192,7 +223,7 @@ func (s *Site) renderPaginator(p *pageState, layouts []string) error {
if err := s.renderAndWritePage(
&s.PathSpec.ProcessingStats.PaginatorPages,
p.Title(),
- targetPaths.TargetFilename, p, layouts...); err != nil {
+ targetPaths.TargetFilename, p, templ); err != nil {
return err
}
@@ -220,15 +251,14 @@ func (s *Site) render404() error {
return err
}
- nfLayouts := []string{"404.html"}
-
+ templ := s.lookupLayouts("404.html")
targetPath := p.targetPaths().TargetFilename
if targetPath == "" {
return errors.New("failed to create targetPath for 404 page")
}
- return s.renderAndWritePage(&s.PathSpec.ProcessingStats.Pages, "404 page", targetPath, p, nfLayouts...)
+ return s.renderAndWritePage(&s.PathSpec.ProcessingStats.Pages, "404 page", targetPath, p, templ)
}
func (s *Site) renderSitemap() error {
@@ -255,9 +285,9 @@ func (s *Site) renderSitemap() error {
return errors.New("failed to create targetPath for sitemap")
}
- smLayouts := []string{"sitemap.xml", "_default/sitemap.xml", "_internal/_default/sitemap.xml"}
+ templ := s.lookupLayouts("sitemap.xml", "_default/sitemap.xml", "_internal/_default/sitemap.xml")
- return s.renderAndWriteXML(&s.PathSpec.ProcessingStats.Sitemaps, "sitemap", targetPath, p, smLayouts...)
+ return s.renderAndWriteXML(&s.PathSpec.ProcessingStats.Sitemaps, "sitemap", targetPath, p, templ)
}
func (s *Site) renderRobotsTXT() error {
@@ -282,9 +312,9 @@ func (s *Site) renderRobotsTXT() error {
return err
}
- rLayouts := []string{"robots.txt", "_default/robots.txt", "_internal/_default/robots.txt"}
+ templ := s.lookupLayouts("robots.txt", "_default/robots.txt", "_internal/_default/robots.txt")
- return s.renderAndWritePage(&s.PathSpec.ProcessingStats.Pages, "Robots Txt", p.targetPaths().TargetFilename, p, rLayouts...)
+ return s.renderAndWritePage(&s.PathSpec.ProcessingStats.Pages, "Robots Txt", p.targetPaths().TargetFilename, p, templ)
}