diff options
author | Bjørn Erik Pedersen <[email protected]> | 2019-04-10 10:11:51 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2019-04-12 09:18:59 +0200 |
commit | f7375c497239115cd30ae42af6b4d298e4e7ad7d (patch) | |
tree | cb21a9da3a26a0e151b11d5117454c74b3a95136 /hugolib/page__paginator.go | |
parent | 7966c0b5b7b2297527f8be9040b793de5e4e3f48 (diff) | |
download | hugo-f7375c497239115cd30ae42af6b4d298e4e7ad7d.tar.gz hugo-f7375c497239115cd30ae42af6b4d298e4e7ad7d.zip |
Fix paginator refresh on server change
Fixes #5838
Diffstat (limited to 'hugolib/page__paginator.go')
-rw-r--r-- | hugolib/page__paginator.go | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/hugolib/page__paginator.go b/hugolib/page__paginator.go index 020d08089..026546742 100644 --- a/hugolib/page__paginator.go +++ b/hugolib/page__paginator.go @@ -19,16 +19,31 @@ import ( "github.com/gohugoio/hugo/resources/page" ) -type pagePaginator struct { - paginatorInit sync.Once - current *page.Pager +func newPagePaginator(source *pageState) *pagePaginator { + return &pagePaginator{ + source: source, + pagePaginatorInit: &pagePaginatorInit{}, + } +} +type pagePaginator struct { + *pagePaginatorInit source *pageState } +type pagePaginatorInit struct { + init sync.Once + current *page.Pager +} + +// reset resets the paginator to allow for a rebuild. +func (p *pagePaginator) reset() { + p.pagePaginatorInit = &pagePaginatorInit{} +} + func (p *pagePaginator) Paginate(seq interface{}, options ...interface{}) (*page.Pager, error) { var initErr error - p.paginatorInit.Do(func() { + p.init.Do(func() { pagerSize, err := page.ResolvePagerSize(p.source.s.Cfg, options...) if err != nil { initErr = err @@ -56,7 +71,7 @@ func (p *pagePaginator) Paginate(seq interface{}, options ...interface{}) (*page func (p *pagePaginator) Paginator(options ...interface{}) (*page.Pager, error) { var initErr error - p.paginatorInit.Do(func() { + p.init.Do(func() { pagerSize, err := page.ResolvePagerSize(p.source.s.Cfg, options...) if err != nil { initErr = err @@ -81,7 +96,3 @@ func (p *pagePaginator) Paginator(options ...interface{}) (*page.Pager, error) { return p.current, nil } - -func (p *pagePaginator) rewind() { - p.current = p.current.First() -} |