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 /markup/converter/hooks/hooks.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 'markup/converter/hooks/hooks.go')
-rw-r--r-- | markup/converter/hooks/hooks.go | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/markup/converter/hooks/hooks.go b/markup/converter/hooks/hooks.go index bdc38f119..54babd320 100644 --- a/markup/converter/hooks/hooks.go +++ b/markup/converter/hooks/hooks.go @@ -32,8 +32,7 @@ type AttributesProvider interface { // LinkContext is the context passed to a link render hook. type LinkContext interface { - // The Page being rendered. - Page() any + PageProvider // The link URL. Destination() string @@ -64,6 +63,7 @@ type ImageLinkContext interface { type CodeblockContext interface { AttributesProvider text.Positioner + PageProvider // Chroma highlighting processing options. This will only be filled if Type is a known Chroma Lexer. Options() map[string]any @@ -76,9 +76,6 @@ type CodeblockContext interface { // Zero-based ordinal for all code blocks in the current document. Ordinal() int - - // The owning Page. - Page() any } type AttributesOptionsSliceProvider interface { @@ -101,8 +98,7 @@ type IsDefaultCodeBlockRendererProvider interface { // HeadingContext contains accessors to all attributes that a HeadingRenderer // can use to render a heading. type HeadingContext interface { - // Page is the page containing the heading. - Page() any + PageProvider // Level is the level of the header (i.e. 1 for top-level, 2 for sub-level, etc.). Level() int // Anchor is the HTML id assigned to the heading. @@ -116,6 +112,16 @@ type HeadingContext interface { AttributesProvider } +type PageProvider interface { + // Page is the page being rendered. + Page() any + + // PageInner may be different than Page when .RenderShortcodes is in play. + // The main use case for this is to include other pages' markdown into the current page + // but resolve resources and pages relative to the original. + PageInner() any +} + // HeadingRenderer describes a uniquely identifiable rendering hook. type HeadingRenderer interface { // RenderHeading writes the rendered content to w using the data in w. |