How can I get a relative URL of a resource image?

Hi there !

I have an issue when getting the .RelPermalink of a resource while having relativeURLs = true in my config.

I would expect it to build a relative URL from the current context, like it does for links between pages, but instead I still get an absolute URL from the root folder.

For example, calling .RelPermalink on a post’s resource from the home will give:

/post/mypost/myimage.jpg

But I would expect it to be:

./post/mypost/myimage.jpg

Shouldn’t it ?
Thank you for your time !

The relativeURLs = true does not change the value of .RelPermalink in any way, but using relative links in the first place is a must if you want relativeURLs = true to work.

That setting does replacements of the generated HTML.

You give much to little information to determine what’s happening in your case.

I have a similar case with my testsite where I can build Development, Production and Local versions with my configs. So for the local version I wanted exactly the relative path with ./ in front as you describe. My working solution in my config_local.toml:

baseURL       = "/"
relativeURLs  = true
uglyurls      = true

I call this in my package.json with

HUGO_ENV=local Hugo --config config.toml,config_local.toml

Hope this helps.