Using goldmark renderHooks.link with multilingual

Hi all!

As I understand useEmbedded = auto with [markup.goldmark.renderHooks.link]:

The embedded link render hook resolves internal Markdown destinations by looking for a matching page, falling back to a matching page resource, then falling back to a matching global resource. Remote destinations are passed through, and the render hook will not throw an error or warning if unable to resolve a destination.

For a multilingual site we have been using markdown links like [a link]({{< relref "/page" >}}.

This works well if I have a translation of that page, such that links will stay in the correct lang.

content
├── getting_started
│   ├── index.fr.md
│   └── index.md
├── apage
│   ├── index.fr.md
│   └── index.md

apage/index.fr.md

[a link]({{< relref "/getting_started" >}})

will link to the page SITE/fr/getting_started.
while
apage/index.md

[a link]({{< relref "/getting_started" >}})

will link to the page SITE/getting_started.

I was under the impression that using the renderHooks.link with useEmbedded = auto would allow me to use simpler markdown links and still have things work similar to relref.

But:
apage/index.fr.md

[a link](/getting_started>)

will link to the page SITE/getting_started. (as opposed to SITE/fr/getting_started).

Was I mistaken or is there a configuration perhaps that I’m missing somewhere?

Relevant lang section of hugo.toml:

...
[languages]
  [languages.en]
    languageCode = 'en-US'
    languageName = 'English'
    timeZone = 'America/New_York'
    title = 'RawPedia'
    weight = 1
    [languages.en.pagination]
      path = 'page'
  [languages.fr]
    languageCode = 'fr'
    languageName = 'Français'
    timeZone = 'America/New_York'
    title = 'RawPedia'
    weight = 1
    [languages.fr.pagination]
      path = 'page'
...

I am unable to reproduce any unexpected behavior, but maybe this test site is missing something:

git clone --single-branch -b hugo-forum-topic-56696 https://github.com/jmooring/hugo-testing hugo-forum-topic-56696
cd hugo-forum-topic-56696
hugo server

Notice that the site configuration doesn’t contain any render hook settings; it doesn’t need to. The embedded link and image render hooks are automatically enabled for multilingual single-host projects provided that duplicateResourceFiles is false (the default).


Also note: if you continue to use the relref shortcode, be sure to call it using the Markdown notation. See examples.

1 Like

Well, thanks (yet again) for the help. :slight_smile: Your example worked perfectly.

I set useEmbedded = always and it helped me discover some poorly formatted markdown links that might have been causing the issue.

[edit]: after further hunting, my theme had defined a custom render-link.html which is why it was working with always but failing with auto. Duh. :zany_face:

1 Like

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