Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion layouts/_partials/utilities/GetPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,21 @@
{{- if not $isExternal -}}
{{- $ref = $page.GetPage $url -}}

{{/* Fallback to a site-wide lookup. Page.GetPage resolves relative
references against Hugo's active rendering context (the `page`
global), not the receiver page. When content is processed from a
foreign render — e.g. an output format whose layout iterates other
pages and reads .Plain / .Content / .Summary — the active context
is the driving page, and the receiver-based lookup returns nil.
site.GetPage is context-independent and finds the page by name. */}}
{{ if not $ref }}
{{- $ref = site.GetPage $url -}}
{{ end }}

{{ if not $ref }}
{{ $match := partial "utilities/GetStaticURL" (dict "url" $url) }}
{{ if not (hasSuffix $match "/") }}{{ $match = printf "%s/" $match }}{{ end }}

{{ $matches := where site.AllPages "RelPermalink" "like" (printf "%s$" $match) }}
{{ if eq (len $matches) 1 }}
{{ $ref = index $matches 0 }}
Expand Down
9 changes: 8 additions & 1 deletion layouts/_partials/utilities/GetStaticURL.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
{{ if not $url }}{{ $url = "/" }}{{ end }}

{{ $lang := site.Language.Lang }}
{{ $base := strings.TrimSuffix (printf "%s/" $lang) site.Home.RelPermalink }}
{{/* site.Home.RelPermalink returns the active output's permalink, so
during a non-HTML output render (e.g. a custom searchindex / RSS /
custom JSON output) it would inject that output's path here and
produce a nonsensical base URL. The HTML output's permalink is the
canonical site root and remains stable across render contexts. */}}
{{ $homeURL := site.Home.RelPermalink }}
{{ with site.Home.OutputFormats.Get "html" }}{{ $homeURL = .RelPermalink }}{{ end }}
{{ $base := strings.TrimSuffix (printf "%s/" $lang) $homeURL }}

{{ $url = partial "utilities/URLJoin.html" (dict "base" $base "path" $url) }}
{{ end }}
Expand Down
Loading