mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
hugolib: Must recreate Paginator on live-reload
The structure may potentially have changed, and then it fails. Fixes #3315
This commit is contained in:
parent
e765b43e2b
commit
45c7452668
2 changed files with 18 additions and 12 deletions
|
@ -78,13 +78,17 @@ func newPageOutput(p *Page, createCopy bool, f output.Format) (*PageOutput, erro
|
||||||
|
|
||||||
// copy creates a copy of this PageOutput with the lazy sync.Once vars reset
|
// copy creates a copy of this PageOutput with the lazy sync.Once vars reset
|
||||||
// so they will be evaluated again, for word count calculations etc.
|
// so they will be evaluated again, for word count calculations etc.
|
||||||
func (p *PageOutput) copy() *PageOutput {
|
func (p *PageOutput) copyWithFormat(f output.Format) (*PageOutput, error) {
|
||||||
c, err := newPageOutput(p.Page, true, p.outputFormat)
|
c, err := newPageOutput(p.Page, true, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
c.paginator = p.paginator
|
c.paginator = p.paginator
|
||||||
return c
|
return c, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PageOutput) copy() (*PageOutput, error) {
|
||||||
|
return p.copyWithFormat(p.outputFormat)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PageOutput) layouts(layouts ...string) ([]string, error) {
|
func (p *PageOutput) layouts(layouts ...string) ([]string, error) {
|
||||||
|
@ -142,6 +146,9 @@ func (p *Page) Render(layout ...string) template.HTML {
|
||||||
}
|
}
|
||||||
|
|
||||||
p.pageOutputInit.Do(func() {
|
p.pageOutputInit.Do(func() {
|
||||||
|
if p.mainPageOutput != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
// If Render is called in a range loop, the page output isn't available.
|
// If Render is called in a range loop, the page output isn't available.
|
||||||
// So, create one.
|
// So, create one.
|
||||||
outFormat := p.outputFormats[0]
|
outFormat := p.outputFormats[0]
|
||||||
|
|
|
@ -75,14 +75,10 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
|
||||||
)
|
)
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
page.pageOutputInit.Do(func() {
|
pageOutput, err = newPageOutput(page, false, outFormat)
|
||||||
var po *PageOutput
|
page.mainPageOutput = pageOutput
|
||||||
po, err = newPageOutput(page, false, outFormat)
|
|
||||||
page.mainPageOutput = po
|
|
||||||
})
|
|
||||||
pageOutput = page.mainPageOutput
|
|
||||||
} else {
|
} else {
|
||||||
pageOutput, err = newPageOutput(page, true, outFormat)
|
pageOutput, err = page.mainPageOutput.copyWithFormat(outFormat)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -159,7 +155,10 @@ func (s *Site) renderPaginator(p *PageOutput) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
pagerNode := p.copy()
|
pagerNode, err := p.copy()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
pagerNode.paginator = pager
|
pagerNode.paginator = pager
|
||||||
if pager.TotalPages() > 0 {
|
if pager.TotalPages() > 0 {
|
||||||
|
|
Loading…
Reference in a new issue