In my Hugo website, baseUrl is set to:website.com/variable.
If an image element is in .html (< img src="/images/image.png" >), the baseUrl is applied and the final url is this:website.com/variable/images/image.png/
If an image element is in .js (img.src = “/images/image.png”), the baseUrl is not applied and the final url is incorrect:website.com/images/image.png/
I tried to add a custom output format for js in config.toml, but it didn’t work:
[mediaTypes.“application/javascript”]
suffixes = [“js”]
Is there a way to access template variables in .js files?
No, I may be wrong, but from what I saw, Hugo does not phrase (apart of minification) javascript hence you cannot add for example {{ .Site.BaseURL }} into it unless you process your Javascript inside a shortcode or partial, then this may actually work.