absURL with relativeUrls = true generates absulte URLs inside range

In the following code from the beautifulhugo template:

<div id="header-big-imgs" data-num-img={{len $bigimg}} {{range $i, $img := $bigimg}}data-img-src-{{add $i 1}}="{{$img.src | absURL }}" {{ if $img.desc}}data-img-desc-{{add $i 1}}="{{$img.desc}}"{{end}}{{end}}></div>

{{$img.src | absURL }} will always return an absolute url, regardless of the value of relativeUrls. So with the following config:

baseURL = "http://host.com/"
relativeUrls = true

And data:

$img.src = "/img/test.png"
Page being rendered = "http://host.com/post/first-post"

I’d expect {{$img.src | absURL }} to render ../../img/test.png but I instead get /img/test.png.

Is this a bug or am I misunderstanding how absUrl works with relativeUrls = true?

It is a known limitation. Use the search

Hello bep,

If it’s a known limitation, shouldn’t it say so in the absURL and/or range docs? I can’t find a reference to this limitation anywhere.

I have actually spent quite a lot of time researching this, and found some related posts but nothing specific about this. Have I missed something obvious?


This is about relativeURLs.


Yes, that’s true. There is no mention about that limitation in the relativeUrls docs neither.

This might seem like a minor issue, but with the increasing use of IPFS to serve websites (as it is my case) the reliable use of relative URLs is bound to become more important.

I’d be happy to do a PR update the docs, but unfortunately I don’t consider myself authoritative enough as I don’t really know what the actual reason for the limitation is.