My problem is: I don’t know how to generate “dotted” relative URLs from those.
In my shortcode, I expected {{ relURL (.Get 0) }} to generate a dotted URL relative to the current page, but it’s left unchanged ("/img/carousel/de/1.png" instead of "../../img/carousel/de/1.png").
What am I missing? Or: what is the Hugo way to do this?
Are these images existing at web-root from there going /img/carousel and so on? Then using imageConfig on the real files might help. You load the images, then you got plenty of properties on the file object including relative links.
If the files are within a page bundle then you probably need to change your short code to work with page ressouces. Those again have plenty of properties which will help with links.
Then using imageConfig on the real files might help. You load the images, then you got plenty of properties on the file object including relative links.
I’m confused: I just tried imageConfig, but as the doc says, it just returns the height, width, and color model of the image, nothing about the file itself…
Sorry about that. I did not mean imageConfig, but readFile. I used both functions in the same context in my template and just confused them up.
Have a look at this page:
When you range through the files you get these properties here:
I think the example in the first link might even fit perfectly to your shortcode. You could just give it a path and then name the files alphabetically so they are loaded in the order you prefer.
The “don’t want dotted URLs”: You should prefer paths from your webroot, like “/images/something/image.jpg” instead of “…/…/images/something/image.jpg”. Apart from the first version being a bit shorter - if you move the file up one level or down one level your dotted navigation breaks. the absolute will always go from domain root, as long as you have a ‘/’ in the beginning.
First thing is, I had to rewrite layouts to pipe asset URLs to relURL, but that’s no big deal.
However in this setup here’s what happens when I use my shortcode in the page “/de”:
For context: .Page.RelPermalink returns “/documentation/de/” .Get 0 is “/img/carousel/de/1.png”
Ok I now know the obvious reason why I used relativeURLs = true and “dotted” relative URLs in the first place: I deploy this documentation in different environments (staging, prod), and using absolute URLs means I’d have to make a new build for each one (which defeats the idea of having different environments).
Also what I ended up doing is to generate the “…/…/…/” prefix up to the root, based on the page’s .RelPermalink, which I apply to the list of URLs passed as params to the shortcode: