mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
@@ -19,6 +19,16 @@ import (
|
||||
"github.com/gohugoio/hugo/lazy"
|
||||
)
|
||||
|
||||
// OutputFormatContentProvider represents the method set that is "outputFormat aware" and that we
|
||||
// provide lazy initialization for in case they get invoked outside of their normal rendering context, e.g. via .Translations.
|
||||
// Note that this set is currently not complete, but should cover the most common use cases.
|
||||
// For the others, the implementation will be from the page.NoopPage.
|
||||
type OutputFormatContentProvider interface {
|
||||
ContentProvider
|
||||
TableOfContentsProvider
|
||||
PageRenderProvider
|
||||
}
|
||||
|
||||
// LazyContentProvider initializes itself when read. Each method of the
|
||||
// ContentProvider interface initializes a content provider and shares it
|
||||
// with other methods.
|
||||
@@ -27,13 +37,13 @@ import (
|
||||
// will be needed. Must create via NewLazyContentProvider.
|
||||
type LazyContentProvider struct {
|
||||
init *lazy.Init
|
||||
cp ContentProvider
|
||||
cp OutputFormatContentProvider
|
||||
}
|
||||
|
||||
// NewLazyContentProvider returns a LazyContentProvider initialized with
|
||||
// function f. The resulting LazyContentProvider calls f in order to
|
||||
// retrieve a ContentProvider
|
||||
func NewLazyContentProvider(f func() (ContentProvider, error)) *LazyContentProvider {
|
||||
func NewLazyContentProvider(f func() (OutputFormatContentProvider, error)) *LazyContentProvider {
|
||||
lcp := LazyContentProvider{
|
||||
init: lazy.New(),
|
||||
cp: NopPage,
|
||||
@@ -49,11 +59,6 @@ func NewLazyContentProvider(f func() (ContentProvider, error)) *LazyContentProvi
|
||||
return &lcp
|
||||
}
|
||||
|
||||
func (lcp *LazyContentProvider) Init() ContentProvider {
|
||||
lcp.init.Do()
|
||||
return lcp.cp
|
||||
}
|
||||
|
||||
func (lcp *LazyContentProvider) Reset() {
|
||||
lcp.init.Reset()
|
||||
}
|
||||
@@ -102,3 +107,18 @@ func (lcp *LazyContentProvider) Len() int {
|
||||
lcp.init.Do()
|
||||
return lcp.cp.Len()
|
||||
}
|
||||
|
||||
func (lcp *LazyContentProvider) Render(layout ...string) (template.HTML, error) {
|
||||
lcp.init.Do()
|
||||
return lcp.cp.Render(layout...)
|
||||
}
|
||||
|
||||
func (lcp *LazyContentProvider) RenderString(args ...interface{}) (template.HTML, error) {
|
||||
lcp.init.Do()
|
||||
return lcp.cp.RenderString(args...)
|
||||
}
|
||||
|
||||
func (lcp *LazyContentProvider) TableOfContents() template.HTML {
|
||||
lcp.init.Do()
|
||||
return lcp.cp.TableOfContents()
|
||||
}
|
||||
|
Reference in New Issue
Block a user