Skip to content

Commit 45c7452

Browse files
committed
hugolib: Must recreate Paginator on live-reload
The structure may potentially have changed, and then it fails. Fixes #3315
1 parent e765b43 commit 45c7452

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

‎hugolib/page_output.go‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,17 @@ func newPageOutput(p *Page, createCopy bool, f output.Format) (*PageOutput, erro
7878

7979
// copy creates a copy of this PageOutput with the lazy sync.Once vars reset
8080
// so they will be evaluated again, for word count calculations etc.
81-
func (p *PageOutput) copy() *PageOutput {
82-
c, err := newPageOutput(p.Page, true, p.outputFormat)
81+
func (p *PageOutput) copyWithFormat(f output.Format) (*PageOutput, error) {
82+
c, err := newPageOutput(p.Page, true, f)
8383
if err != nil {
84-
panic(err)
84+
return nil, err
8585
}
8686
c.paginator = p.paginator
87-
return c
87+
return c, nil
88+
}
89+
90+
func (p *PageOutput) copy() (*PageOutput, error) {
91+
return p.copyWithFormat(p.outputFormat)
8892
}
8993

9094
func (p *PageOutput) layouts(layouts ...string) ([]string, error) {
@@ -142,6 +146,9 @@ func (p *Page) Render(layout ...string) template.HTML {
142146
}
143147

144148
p.pageOutputInit.Do(func() {
149+
if p.mainPageOutput != nil {
150+
return
151+
}
145152
// If Render is called in a range loop, the page output isn't available.
146153
// So, create one.
147154
outFormat := p.outputFormats[0]

‎hugolib/site_render.go‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,10 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
7575
)
7676

7777
if i == 0 {
78-
page.pageOutputInit.Do(func() {
79-
var po *PageOutput
80-
po, err = newPageOutput(page, false, outFormat)
81-
page.mainPageOutput = po
82-
})
83-
pageOutput = page.mainPageOutput
78+
pageOutput, err = newPageOutput(page, false, outFormat)
79+
page.mainPageOutput = pageOutput
8480
} else {
85-
pageOutput, err = newPageOutput(page, true, outFormat)
81+
pageOutput, err = page.mainPageOutput.copyWithFormat(outFormat)
8682
}
8783

8884
if err != nil {
@@ -159,7 +155,10 @@ func (s *Site) renderPaginator(p *PageOutput) error {
159155
continue
160156
}
161157

162-
pagerNode := p.copy()
158+
pagerNode, err := p.copy()
159+
if err != nil {
160+
return err
161+
}
163162

164163
pagerNode.paginator = pager
165164
if pager.TotalPages() > 0 {

0 commit comments

Comments
 (0)