panic(fmt.Sprintf("pageOutput is nil for output idx %d", idx))
}
- // We attempt to assign pageContentOutputs while preparing each site
- // for rendering and before rendering each site. This lets us share
- // content between page outputs to conserve resources. But if a template
- // unexpectedly calls a method of a ContentProvider that is not yet
- // initialized, we assign a LazyContentProvider that performs the
- // initialization just in time.
- p.pageOutput.ContentProvider = page.NewLazyContentProvider(func() (page.ContentProvider, error) {
- cp, err := newPageContentOutput(p, p.pageOutput)
- if err != nil {
- return nil, err
- }
- return cp, nil
- })
-
// Reset any built paginator. This will trigger when re-rendering pages in
// server mode.
if isRenderingSite && p.pageOutput.paginator != nil && p.pageOutput.paginator.current != nil {
}
}
p.pageOutput.initContentProvider(cp)
- p.pageOutput.cp = cp
+ } else {
+ // We attempt to assign pageContentOutputs while preparing each site
+ // for rendering and before rendering each site. This lets us share
+ // content between page outputs to conserve resources. But if a template
+ // unexpectedly calls a method of a ContentProvider that is not yet
+ // initialized, we assign a LazyContentProvider that performs the
+ // initialization just in time.
+ if lcp, ok := (p.pageOutput.ContentProvider.(*page.LazyContentProvider)); ok {
+ lcp.Reset()
+ } else {
+ p.pageOutput.ContentProvider = page.NewLazyContentProvider(func() (page.ContentProvider, error) {
+ cp, err := newPageContentOutput(p, p.pageOutput)
+ if err != nil {
+ return nil, err
+ }
+ return cp, nil
+ })
+ }
}
return nil
return &lcp
}
+func (lcp *LazyContentProvider) Reset() {
+ lcp.init.Reset()
+}
+
func (lcp *LazyContentProvider) Content() (interface{}, error) {
lcp.init.Do()
return lcp.cp.Content()
func (lcp *LazyContentProvider) Summary() template.HTML {
lcp.init.Do()
return lcp.cp.Summary()
-
}
func (lcp *LazyContentProvider) Truncated() bool {
lcp.init.Do()
return lcp.cp.Truncated()
-
}
func (lcp *LazyContentProvider) FuzzyWordCount() int {
lcp.init.Do()
return lcp.cp.FuzzyWordCount()
-
}
func (lcp *LazyContentProvider) WordCount() int {
lcp.init.Do()
return lcp.cp.WordCount()
-
}
func (lcp *LazyContentProvider) ReadingTime() int {
lcp.init.Do()
return lcp.cp.ReadingTime()
-
}
func (lcp *LazyContentProvider) Len() int {
lcp.init.Do()
return lcp.cp.Len()
-
}