mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
hugolib: Wrap pageOutput create in sync.Once
This commit is contained in:
parent
0aaf3c56a5
commit
9a0aa5fdbe
4 changed files with 32 additions and 6 deletions
|
@ -244,6 +244,7 @@ type pageInit struct {
|
|||
languageInit sync.Once
|
||||
pageMenusInit sync.Once
|
||||
pageMetaInit sync.Once
|
||||
pageOutputInit sync.Once
|
||||
plainInit sync.Once
|
||||
plainWordsInit sync.Once
|
||||
renderingConfigInit sync.Once
|
||||
|
|
|
@ -108,6 +108,21 @@ func (p *PageOutput) Render(layout ...string) template.HTML {
|
|||
|
||||
// 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...)
|
||||
}
|
||||
|
||||
|
|
|
@ -60,22 +60,31 @@ func (s *Site) renderPages() error {
|
|||
|
||||
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
|
||||
|
||||
|
|
|
@ -180,6 +180,7 @@ func (t *GoHTMLTemplate) executeTemplate(context interface{}, w io.Writer, layou
|
|||
for _, layout := range layouts {
|
||||
templ := t.Lookup(layout)
|
||||
if templ == nil {
|
||||
// TODO(bep) output
|
||||
layout += ".html"
|
||||
templ = t.Lookup(layout)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue