diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-04-11 17:46:18 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-04-15 09:49:57 +0200 |
commit | df11327ba90179747be2b25574ac48c2f336b298 (patch) | |
tree | 70f7487cee6815109fc325ed0619130bb29834ca /hugolib/page__per_output.go | |
parent | a18e2bcb9a2c556e03dc7e790b0343c83163877a (diff) | |
download | hugo-df11327ba90179747be2b25574ac48c2f336b298.tar.gz hugo-df11327ba90179747be2b25574ac48c2f336b298.zip |
Pass .RenderShortcodes' Page to render hooks as .PageInner
The main use case for this is to resolve links and resources (e.g. images) relative to the included `Page`.
A typical `include` would similar to this:
```handlebars
{{ with site.GetPage (.Get 0) }}
{{ .RenderShortcodes }}
{{ end }}
```
And when used in a Markdown file:
```markdown
{{% include "/posts/p1" %}}
```
Any render hook triggered while rendering `/posts/p1` will get `/posts/p1` when calling `.PageInner`.
Note that
* This is only relevant for shortcodes included with `{{%` that calls `.RenderShortcodes`.
* `.PageInner` is available in all render hooks that, before this commit, received `.Page`.
* `.PageInner` will fall back to the value of `.Page` if not relevant and will always have a value.
Fixes #12356
Diffstat (limited to 'hugolib/page__per_output.go')
-rw-r--r-- | hugolib/page__per_output.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go index fac719ea9..4ff67c074 100644 --- a/hugolib/page__per_output.go +++ b/hugolib/page__per_output.go @@ -30,6 +30,7 @@ import ( "github.com/spf13/cast" "github.com/gohugoio/hugo/markup/converter/hooks" + "github.com/gohugoio/hugo/markup/goldmark/hugocontext" "github.com/gohugoio/hugo/markup/highlight/chromalexers" "github.com/gohugoio/hugo/markup/tableofcontents" @@ -68,8 +69,9 @@ var ( func newPageContentOutput(po *pageOutput) (*pageContentOutput, error) { cp := &pageContentOutput{ - po: po, - renderHooks: &renderHooks{}, + po: po, + renderHooks: &renderHooks{}, + otherOutputs: make(map[uint64]*pageContentOutput), } return cp, nil } @@ -83,6 +85,10 @@ type renderHooks struct { type pageContentOutput struct { po *pageOutput + // Other pages involved in rendering of this page, + // typically included with .RenderShortcodes. + otherOutputs map[uint64]*pageContentOutput + contentRenderedVersion int // Incremented on reset. contentRendered bool // Set on content render. @@ -165,6 +171,13 @@ func (pco *pageContentOutput) RenderShortcodes(ctx context.Context) (template.HT cb(pco, ct) } + if tpl.Context.IsInGoldmark.Get(ctx) { + // This content will be parsed and rendered by Goldmark. + // Wrap it in a special Hugo markup to assign the correct Page from + // the stack. + c = hugocontext.Wrap(c, pco.po.p.pid) + } + return helpers.BytesToHTML(c), nil } |