ref: 9032a228b01906eea7ad92269c5bad109c333418
parent: 54a2790fce03ef4bc7798a7e4c38ba5bfffe2314
author: Noah Campbell <noahcampbell@gmail.com>
date: Wed Oct 2 07:05:57 EDT 2013
Better handle missing layouts Panic is too extreme. Instead the library will write out a message in verbose mode.
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -401,7 +401,7 @@
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 @@
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 @@
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 @@
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 {--
⑨