ref: 9a0aa5fdbe3ef35b7cc1dd756f54f1b219225bfc
parent: 0aaf3c56a511c6582db4dbfb28879e964e6f2d92
author: Bjørn Erik Pedersen <[email protected]>
date: Sun Mar 26 07:45:12 EDT 2017
hugolib: Wrap pageOutput create in sync.Once
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -244,6 +244,7 @@
languageInit sync.Once
pageMenusInit sync.Once
pageMetaInit sync.Once
+ pageOutputInit sync.Once
plainInit sync.Once
plainWordsInit sync.Once
renderingConfigInit sync.Once
--- a/hugolib/page_output.go
+++ b/hugolib/page_output.go
@@ -108,6 +108,21 @@
// TODO(bep) output
func (p *Page) Render(layout ...string) template.HTML {
+ p.pageOutputInit.Do(func() {
+ // If Render is called in a range loop, the page output isn't available.
+ // So, create one.
+ outFormat := p.outputFormats[0]
+ pageOutput, err := newPageOutput(p, true, outFormat)
+
+ if err != nil {
+ p.s.Log.ERROR.Printf("Failed to create output page for type %q for page %q: %s", outFormat.Name, p, err)
+ return
+ }
+
+ p.mainPageOutput = pageOutput
+
+ })
+
return p.mainPageOutput.Render(layout...)
}
--- a/hugolib/site_render.go
+++ b/hugolib/site_render.go
@@ -60,22 +60,31 @@
func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.WaitGroup) {
defer wg.Done()
- var mainPageOutput *PageOutput
for page := range pages {
for i, outFormat := range page.outputFormats {
- pageOutput, err := newPageOutput(page, i > 0, outFormat)
+ var (
+ pageOutput *PageOutput
+ err error
+ )
+ if i == 0 {
+ page.pageOutputInit.Do(func() {
+ var po *PageOutput
+ po, err = newPageOutput(page, false, outFormat)
+ page.mainPageOutput = po
+ })
+ pageOutput = page.mainPageOutput
+ } else {
+ pageOutput, err = newPageOutput(page, true, outFormat)
+ }
+
if err != nil {
s.Log.ERROR.Printf("Failed to create output page for type %q for page %q: %s", outFormat.Name, page, err)
continue
}
- if i == 0 {
- mainPageOutput = pageOutput
- }
- page.mainPageOutput = mainPageOutput
var layouts []string
--- a/tpl/tplimpl/template.go
+++ b/tpl/tplimpl/template.go
@@ -180,6 +180,7 @@
for _, layout := range layouts {
templ := t.Lookup(layout)
if templ == nil {
+ // TODO(bep) output
layout += ".html"
templ = t.Lookup(layout)
}