Mysterious HREF (and SRC) corrector

I’m using relativeURLs: true in my config and
I noticed that strings inserted as value of the HREF attribute get checked and corrected. Concretely, when a page living at /comics/comicsname/ uses this piece of template:

{{ $url := "/comics/comicsname/comicsname-thumb.jpg" }}
<a href="{{ $url}}" data-thumb="{{ $url }}">link here</a>

the output is:

` <a href="../../comics/comicsname/comicsname-thumb.jpg" data-thumb="/comics/comicsname/comicsname-thumb.jpg">link here</a>`

I want to duplicate the href-correction behavior for other attributes where I need to have this correction (like “data-thumb” for use as a Fancybox parameter).

Is it possible?

And if not, is it possible to turn this behavior off without having to use absoluteURLs?

Thanks for any hints.

Maybe {{ $url | relURL }}.

Well, that’s the strange thing, in my case what I have in the $url ("/comics/comicsname/comicsname-thumb.jpg") is already the result of the relURL function (in the example in my 1st post I wrote just a simplified reconstruction). So the relURL outputs URLs relative to my site’s base URL but the “mysterious HREF corrector” is modifying that URL relative to the page’s location (page’s location is “/comics/comicsname/”). I wish I found some documentation relating to what’s happening and how to take it into account when building my templates. I also tried various workarounds to render my HTML without the correction but it always wins, almost seems like the correction is happening after the HTML was rendered (!).

This is why we ask folks to share their repos: there’s a lot going on and we can’t see the whole picture from your description.

I recommend you share your site or reproduce this behavior in one you share, and we will definitely get you sorted. :slight_smile:

Ok I created a small site reproducing the behavior here:

Any explanation of what’s happening there is much appreciated.
(I’m not an advanced Hugo user)


this is correct what you see

relativeURLs (false)

Enable this to make all relative URLs relative to content root. Note that this does not affect absolute URLs.

content root means your page location here.

Oh I see now. Thanks for the clarification!

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