diff --git a/layouts/_partials/utilities/GetPage.html b/layouts/_partials/utilities/GetPage.html index 163a483..7947800 100644 --- a/layouts/_partials/utilities/GetPage.html +++ b/layouts/_partials/utilities/GetPage.html @@ -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 }} diff --git a/layouts/_partials/utilities/GetStaticURL.html b/layouts/_partials/utilities/GetStaticURL.html index a4bc0a5..87946cb 100644 --- a/layouts/_partials/utilities/GetStaticURL.html +++ b/layouts/_partials/utilities/GetStaticURL.html @@ -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 }}