mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-14 01:35:53 +00:00
Better handle missing layouts
Panic is too extreme. Instead the library will write out a message in verbose mode.
This commit is contained in:
parent
54a2790fce
commit
9032a228b0
1 changed files with 12 additions and 6 deletions
|
@ -401,7 +401,7 @@ func (s *Site) RenderIndexes() error {
|
||||||
|
|
||||||
var base string
|
var base string
|
||||||
base = plural + "/" + k
|
base = plural + "/" + k
|
||||||
err := s.render(n, base+".html", layout, "_default/indexes.html")
|
err := s.render(n, base+".html", layout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -454,7 +454,7 @@ func (s *Site) RenderLists() error {
|
||||||
n.Data["Pages"] = data
|
n.Data["Pages"] = data
|
||||||
layout := "indexes/" + section + ".html"
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -542,6 +542,12 @@ func (s *Site) render(d interface{}, out string, layouts ...string) (err error)
|
||||||
reader, writer := io.Pipe()
|
reader, writer := io.Pipe()
|
||||||
|
|
||||||
layout := s.findFirstLayout(layouts...)
|
layout := s.findFirstLayout(layouts...)
|
||||||
|
if layout == "" {
|
||||||
|
if s.Config.Verbose {
|
||||||
|
fmt.Printf("Unable to locate layout: %s\n", layouts)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
err = s.renderThing(d, layout, writer)
|
err = s.renderThing(d, layout, writer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -552,13 +558,13 @@ func (s *Site) render(d interface{}, out string, layouts ...string) (err error)
|
||||||
return s.WritePublic(out, reader)
|
return s.WritePublic(out, reader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) findFirstLayout(layouts ...string) string {
|
func (s *Site) findFirstLayout(layouts ...string) (layout string) {
|
||||||
for _, layout := range layouts {
|
for _, layout = range layouts {
|
||||||
if s.Tmpl.Lookup(layout) != nil {
|
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 {
|
func (s *Site) renderThing(d interface{}, layout string, w io.WriteCloser) error {
|
||||||
|
|
Loading…
Add table
Reference in a new issue