mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +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:
@@ -165,10 +165,12 @@ var Context = struct {
|
||||
SetDependencyManagerInCurrentScope func(context.Context, identity.Manager) context.Context
|
||||
DependencyScope hcontext.ContextDispatcher[int]
|
||||
Page hcontext.ContextDispatcher[page]
|
||||
IsInGoldmark hcontext.ContextDispatcher[bool]
|
||||
}{
|
||||
DependencyManagerScopedProvider: hcontext.NewContextDispatcher[identity.DependencyManagerScopedProvider](contextKey("DependencyManagerScopedProvider")),
|
||||
DependencyScope: hcontext.NewContextDispatcher[int](contextKey("DependencyScope")),
|
||||
Page: hcontext.NewContextDispatcher[page](contextKey("Page")),
|
||||
IsInGoldmark: hcontext.NewContextDispatcher[bool](contextKey("IsInGoldmark")),
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
{{- $u := urls.Parse .Destination -}}
|
||||
{{- $src := $u.String -}}
|
||||
{{- if not $u.IsAbs -}}
|
||||
{{- with or (.Page.Resources.Get $u.Path) (resources.Get $u.Path) -}}
|
||||
{{- with or (.PageInner.Resources.Get $u.Path) (resources.Get $u.Path) -}}
|
||||
{{- $src = .RelPermalink -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
{{- $u := urls.Parse .Destination -}}
|
||||
{{- $href := $u.String -}}
|
||||
{{- if strings.HasPrefix $u.String "#" }}
|
||||
{{- $href = printf "%s#%s" .Page.RelPermalink $u.Fragment }}
|
||||
{{- $href = printf "%s#%s" .PageInner.RelPermalink $u.Fragment }}
|
||||
{{- else if not $u.IsAbs -}}
|
||||
{{- with or
|
||||
($.Page.GetPage $u.Path)
|
||||
($.Page.Resources.Get $u.Path)
|
||||
($.PageInner.GetPage $u.Path)
|
||||
($.PageInner.Resources.Get $u.Path)
|
||||
(resources.Get $u.Path)
|
||||
-}}
|
||||
{{- $href = .RelPermalink -}}
|
||||
|
Reference in New Issue
Block a user