mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-28 22:19:59 +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:
@@ -41,6 +41,7 @@ func (b *BufWriter) Flush() error {
|
||||
type Context struct {
|
||||
*BufWriter
|
||||
positions []int
|
||||
pids []uint64
|
||||
ContextData
|
||||
}
|
||||
|
||||
@@ -55,6 +56,30 @@ func (ctx *Context) PopPos() int {
|
||||
return p
|
||||
}
|
||||
|
||||
// PushPid pushes a new page ID to the stack.
|
||||
func (ctx *Context) PushPid(pid uint64) {
|
||||
ctx.pids = append(ctx.pids, pid)
|
||||
}
|
||||
|
||||
// PeekPid returns the current page ID without removing it from the stack.
|
||||
func (ctx *Context) PeekPid() uint64 {
|
||||
if len(ctx.pids) == 0 {
|
||||
return 0
|
||||
}
|
||||
return ctx.pids[len(ctx.pids)-1]
|
||||
}
|
||||
|
||||
// PopPid pops the last page ID from the stack.
|
||||
func (ctx *Context) PopPid() uint64 {
|
||||
if len(ctx.pids) == 0 {
|
||||
return 0
|
||||
}
|
||||
i := len(ctx.pids) - 1
|
||||
p := ctx.pids[i]
|
||||
ctx.pids = ctx.pids[:i]
|
||||
return p
|
||||
}
|
||||
|
||||
type ContextData interface {
|
||||
RenderContext() converter.RenderContext
|
||||
DocumentContext() converter.DocumentContext
|
||||
|
Reference in New Issue
Block a user