Destination from rel or relref does has unexpect prefix

The markdown text:

[about]({{< ref "/about" >}})
[about]({{< relref "/about" >}})
[about](http://localhost:1313/about/)
[about](/about/)

The render-link.html:

{{ or (hasPrefix .Destination "/") (hasPrefix .Destination site.BaseURL) }} - {{ .Destination }}

Render result:

false - http://localhost:1313/about/
false - /about/
true - http://localhost:1313/about/
true - /about/

So weird!

Then I use index function to check what’s wrong.

render-link.html:

{{ printf "%c%c%c%c%c%c%c" (index .Destination 0) (index .Destination 1) (index .Destination 2) (index .Destination 3) (index .Destination 4) (index .Destination 5) (index .Destination 6) }}

Render result:

HAHAHUG
HAHAHUG
http://
/about/

What’s this?

1 Like

Call a shortcode using the {{< >}} notation

When you call a shortcode using the {{< >}} notation, we replace the shortcode with a placeholder (a short string without whitepace) before sending the content to the markdown render (Goldmark). When we get the rendered content back from Goldmark, we replace the placeholders with the rendered shortcodes.

The placeholder for each shortcode looks like this:

HAHAHUGOSHORTCODE-s0-HBHB   <-- the digit is unique for each short code on the page (ordinal).

In the render hook, when you pull apart the .Destination with string functions, you are looking at the placeholder, not the destination as provided in markdown.

Call a shortcode using the {{% %}} notation

When you call a shortcode using the {{% %}} notation, we replace the shortcode with the contents of the shortcode, then send content Goldmark.

You will get the expected results if you change your markdown to:

[about]({{% ref "/about" %}})

[about]({{% relref "/about" %}})

[about](http://localhost:1313/about/)

[about](/about/)
3 Likes

It works, thank you for your answer.

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