mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
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
This commit is contained in:
@@ -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.
|
||||
|
Reference in New Issue
Block a user