Links rendering issue

Found nothing about my problem. My Hugo version is 0.108, OS is Windows 10 19045.4412

So, I have a YAML-file, which contains the following field:

external_link: https://hello.world.whats.app/lets/go/for/walk

Also, I have a shortcode for reading from this file:

{{- $dataPath := .Get 0 -}}
{{- with split $dataPath "." -}}
    {{- $data := site.Data -}}
    {{- range . -}}
        {{- $data = index $data . -}}
    {{- end -}}
    {{- $data -}}
{{- end -}}

And I have following markdown:

[external link from file]({{< get-site-data "yaml_file.external_link" >}})

[external link hard-coded](https://hello.world.whats.app/lets/go/for/walk)

I created render-link.html hook for processing them, but I see the strange behavior with the link which is read from the file.
When I do

strings.Contains .Destination "http"

It returns false for [external link from file], but true for [external link hard-coded]. I tried to output this .Destination, but it is almost the same for both links.

When I run

{{- $urlData := urls.Parse .Destination -}}
{{- $urlData.IsAbs -}}

It prints false and true correspondingly.

This is an educated guess, but still a guess. Try calling the shortcode using the {{% %}} notation.

Woooooow, it works! Thanks!
But why, what is the reason? :face_with_spiral_eyes:

When using the {{< >}} notation Hugo replaces the shortcode call with a placeholder (e.g., HAHAHUGOSHORTCODE-SOMETHING), then the markdown renderer does its thing, then we replace the placeholder with the rendered shortcode.

So the render hook was seeing HAHAHUGOSHORTCODE-SOMETHING instead of the URL.

Thank you so much I found docs about it and it’s clear now :sweat_smile:

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