Get URL formatted URL string

I would like to save the url and other unrelated data in a JSON object with jsonify. But I can’t figure out how to have hugo rewrite urls that aren’t within href or src attributes. I have tried the relURL, relref functions without any luck.

Is there a function/method that will accept a url string and return in like how Hugo rewrites URLs like in href or src attribute.

For example if there was a link in a template:
<a href="/section-2/page.html">My Link</a>

Would be rewritten base on site’s url settings (for example relative):
<a href="../../section-2/page.html">My Link</a>

I would like to be able to do:
{{ $urlForJSON := someFunction $urlString }}


Any advice on how to accomplish this?

I guess I can make everything absolute but I was hoping for a dynamic solution.

Thanks

Your best bet to get help is to share your code, and follow the directions at Requesting Help. Folks could probably figure out your query if they can clone the site and see the data you are working with. :slight_smile: