mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
df11327ba9
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
28 lines
805 B
HTML
28 lines
805 B
HTML
{{- $u := urls.Parse .Destination -}}
|
|
{{- $href := $u.String -}}
|
|
{{- if strings.HasPrefix $u.String "#" }}
|
|
{{- $href = printf "%s#%s" .PageInner.RelPermalink $u.Fragment }}
|
|
{{- else if not $u.IsAbs -}}
|
|
{{- with or
|
|
($.PageInner.GetPage $u.Path)
|
|
($.PageInner.Resources.Get $u.Path)
|
|
(resources.Get $u.Path)
|
|
-}}
|
|
{{- $href = .RelPermalink -}}
|
|
{{- with $u.RawQuery -}}
|
|
{{- $href = printf "%s?%s" $href . -}}
|
|
{{- end -}}
|
|
{{- with $u.Fragment -}}
|
|
{{- $href = printf "%s#%s" $href . -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- $attributes := dict "href" $href "title" .Title -}}
|
|
<a
|
|
{{- range $k, $v := $attributes -}}
|
|
{{- if $v -}}
|
|
{{- printf " %s=%q" $k $v | safeHTMLAttr -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
>{{ .Text | safeHTML }}</a>
|
|
{{- /**/ -}}
|