mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
Revise the fix for shortcode vs output format nilpointer
We do lazy initialization and (potentially) reuse of an output format's rendered content. We do this evaluation when we start a new rendering a new output format. There are, however, situation where these borders gets crossed (e.g. accessing content from another output format). We have a check for this in place for most cases, but not the content rendering of inner markdown blocks inside shortcodes. This patch applies that same logic to the newly introduced RenderContent method (which is not available from the templates). Fixes #10391
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
"html/template"
|
||||
|
||||
"github.com/gohugoio/hugo/lazy"
|
||||
"github.com/gohugoio/hugo/markup/converter"
|
||||
)
|
||||
|
||||
// OutputFormatContentProvider represents the method set that is "outputFormat aware" and that we
|
||||
@@ -24,6 +25,14 @@ import (
|
||||
// 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 {
|
||||
OutputFormatPageContentProvider
|
||||
|
||||
// for internal use.
|
||||
ContentRenderer
|
||||
}
|
||||
|
||||
// OutputFormatPageContentProvider holds the exported methods from Page that are "outputFormat aware".
|
||||
type OutputFormatPageContentProvider interface {
|
||||
ContentProvider
|
||||
TableOfContentsProvider
|
||||
PageRenderProvider
|
||||
@@ -46,7 +55,7 @@ type LazyContentProvider struct {
|
||||
func NewLazyContentProvider(f func() (OutputFormatContentProvider, error)) *LazyContentProvider {
|
||||
lcp := LazyContentProvider{
|
||||
init: lazy.New(),
|
||||
cp: NopPage,
|
||||
cp: NopCPageContentRenderer,
|
||||
}
|
||||
lcp.init.Add(func() (any, error) {
|
||||
cp, err := f()
|
||||
@@ -122,3 +131,8 @@ func (lcp *LazyContentProvider) TableOfContents() template.HTML {
|
||||
lcp.init.Do()
|
||||
return lcp.cp.TableOfContents()
|
||||
}
|
||||
|
||||
func (lcp *LazyContentProvider) RenderContent(content []byte, renderTOC bool) (converter.Result, error) {
|
||||
lcp.init.Do()
|
||||
return lcp.cp.RenderContent(content, renderTOC)
|
||||
}
|
||||
|
Reference in New Issue
Block a user