aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib
diff options
context:
space:
mode:
authorNoah Campbell <[email protected]>2013-10-02 11:05:57 -0400
committerNoah Campbell <[email protected]>2013-10-08 18:42:02 +0200
commit9032a228b01906eea7ad92269c5bad109c333418 (patch)
treecb9aae52b25775575bfd434bb323bd4b260f5e33 /hugolib
parent54a2790fce03ef4bc7798a7e4c38ba5bfffe2314 (diff)
downloadhugo-9032a228b01906eea7ad92269c5bad109c333418.tar.gz
hugo-9032a228b01906eea7ad92269c5bad109c333418.zip
Better handle missing layouts
Panic is too extreme. Instead the library will write out a message in verbose mode.
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/site.go18
1 files changed, 12 insertions, 6 deletions
diff --git a/hugolib/site.go b/hugolib/site.go
index b83ae3aab..dd069a28a 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -401,7 +401,7 @@ func (s *Site) RenderIndexes() error {
var base string
base = plural + "/" + k
- err := s.render(n, base+".html", layout, "_default/indexes.html")
+ err := s.render(n, base+".html", layout)
if err != nil {
return err
}
@@ -454,7 +454,7 @@ func (s *Site) RenderLists() error {
n.Data["Pages"] = data
layout := "indexes/" + section + ".html"
- err := s.render(n, section, layout, "_default/index.html")
+ err := s.render(n, section, layout, "_default/indexes.html")
if err != nil {
return err
}
@@ -542,6 +542,12 @@ func (s *Site) render(d interface{}, out string, layouts ...string) (err error)
reader, writer := io.Pipe()
layout := s.findFirstLayout(layouts...)
+ if layout == "" {
+ if s.Config.Verbose {
+ fmt.Printf("Unable to locate layout: %s\n", layouts)
+ }
+ return
+ }
go func() {
err = s.renderThing(d, layout, writer)
if err != nil {
@@ -552,13 +558,13 @@ func (s *Site) render(d interface{}, out string, layouts ...string) (err error)
return s.WritePublic(out, reader)
}
-func (s *Site) findFirstLayout(layouts ...string) string {
- for _, layout := range layouts {
+func (s *Site) findFirstLayout(layouts ...string) (layout string) {
+ for _, layout = range layouts {
if s.Tmpl.Lookup(layout) != nil {
- return layout
+ return
}
}
- panic("Unable to find layout.")
+ return ""
}
func (s *Site) renderThing(d interface{}, layout string, w io.WriteCloser) error {