Hugo 0.123.0/.1 breaks .Page.GetPage

Hugo 0.123.0 (and 0.123.1) breaks .Page.GetPage for me.

Basically, I have two files:

content/articles/cpp-cli/passing-native-pointers/index.md
content/articles/cpp-cli/cheat-sheet.md

In the index.md file I have a link like this:

[C++/CLI](cheat-sheet.md)

In my render-link.html render hook I’m using .Page.GetPage to find cheat-sheet.md. This used to work up to Hugo 0.122 but since 0.123 this call returns “nil” (or something falsy).

I noticed https://github.com/gohugoio/hugo/issues/12096 but I’m not sure if it’s the same problem.

Just for reference:

This is related to your usage of .Site.GetPage not .Page.GetPage.

With hugo v0.124.0-DEV-b8ab5c9be the error message is:

Error: error building site: render: failed to render pages: render of “page” failed: “/home/jmooring/temp/devlog/themes/devlog-theme/layouts/_default/single.html:47:9”: execute of template failed: template: _default/single.html:47:9: executing “main” at <.Content>: error calling Content: “/home/jmooring/temp/devlog/content/articles/cpp-cli/passing-native-pointers/index.md:1:1”: “/home/jmooring/temp/devlog/themes/devlog-theme/layouts/_default/_markup/render-link.html:83:32”: execute of template failed: template: _default/_markup/render-link.html:83:32: executing “_default/_markup/render-link.html” at <site.GetPage>: error calling GetPage: page reference “/cheat-sheet.md” is ambiguous

The important parts are:

at <site.GetPage>

“/cheat-sheet.md” is ambiguous

You have two files with that name:

content/articles/docker/cheat-sheet.md
content/articles/cpp-cli/cheat-sheet.md

In content/articles/cpp-cli/passing-native-pointers/index.md you have this markdown:

[C++/CLI](cheat-sheet.md) 

That’s ambiguous, due to your use of .Site.GetPage in your link render hook.

Although I haven’t taken the time to study your link render hook in detail (and I don’t want to), I can tell you from experience that .Page.GetPage is almost always a better choice in this context. You might have a look at Hugo’s embedded link render hook, disabled by default and overriden like any other embedded template:

https://gohugo.io/render-hooks/links/#default

@jmooring Sorry for not being more clear about the problem here.

Basically I have this code:

{{- $targetPage := .Page.GetPage .Destination -}}
{{- if not $targetPage -}}
  {{- /* Page still not found. Try site wide search. */ -}}
  {{- $targetPage = site.GetPage .Destination -}}
{{- end -}}

Up until Hugo 0.122, the call to .Page.GetPage found the page. Now, with Hugo 0.123, .Page.GetPage no longer finds the page - which then results in the fallback to site.GetPage which reports the ambigious reference.

That’s helpful.

Short answer: remove the .md extension from your link destination in markdown.

Longer answer: this is a subtle bug that we will fix.

See https://github.com/gohugoio/hugo/issues/12120

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.