Is there a way to get a relative link to a static file? (something mounted in the static folder)
If I am using the file as a resource, I get use resources.Get or resources.GetMatch to get the resource and then .RelPermalink to get a nice relative link to it.
Is there something similar for static files?
My workaround has been to create the relative paths by hand, but that has been fragile, error prone, and requires updating whenever things move around.
My use case is a little weird:
I need relative links because I am using to build “workbooks” that students will serve on their own computers.
I need a directory of statics (not assets) because there are many files (the static directory is a large tree of library code) - besides the one file that I want to refer to with a link from my Hugo page.
No. static is “just” from the root of the site. (so /static/bla/fasel.jpg becomes {{ site.BaseURL }}/bla/fasel.jpg.
If you
convert your theme/site into a GoHugo Module
mount static into assets
use resource functions to get and process files
Then they will have .RelPermalink. It’s a bit involved, but if you have reasons to work with the files, then you might want to look into this.
The static folder is just a mirroring thing. Nothing is done with it or to it other than copying it over to the site, then creating the site on top of it with the other “folders” (overriding what might be there).
I guess I could mount the static directory as an asset as well, and then get some of the files (I assume the “processed asset” would over-write the thing copied from static).
That’s what I wrote I wouldn’t mount individual files, instead mount the whole static directory to assets/static and then do resources.Get "static/something.jpg" or something like that. Hugo will look into the mount only when you try to “get” something.
You can also do {{ "images/foo.png" | relURL }}. or {{ "images/foo.png" | absURL }}. This does not help when you move files around, but it helps when you change around with the baseURL config (e.g. adding some root to it).
Thanks!
I’ll have to experiment with what happens when both the “get” process and the static process try to create the same file. It shouldn’t matter…