# RelPermalink for Static?

**URL:** <https://discourse.gohugo.io/t/relpermalink-for-static/54599>\
**Category:** support\
**Created:** [May 1, 2025, 10:58pm UTC](https://discourse.gohugo.io/t/relpermalink-for-static/54599 "2025-05-01T22:58:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gleicher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/gleicher/32/11543_2.png) [@gleicher](https://discourse.gohugo.io/u/gleicher)\
**Post date:** [May 1, 2025, 10:58pm UTC](https://discourse.gohugo.io/t/relpermalink-for-static/54599/1 "2025-05-01T22:58:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [May 1, 2025, 11:07pm UTC](https://discourse.gohugo.io/t/relpermalink-for-static/54599/2 "2025-05-01T23:07:50Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![gleicher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/gleicher/32/11543_2.png) [@gleicher](https://discourse.gohugo.io/u/gleicher)\
**Post date:** [May 2, 2025, 1:42am UTC](https://discourse.gohugo.io/t/relpermalink-for-static/54599/3 "2025-05-02T01:42:37Z")

</div>

Thank you! I was expecting that was the answer…

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).

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [May 2, 2025, 2:26am UTC](https://discourse.gohugo.io/t/relpermalink-for-static/54599/4 "2025-05-02T02:26:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [May 2, 2025, 7:07am UTC](https://discourse.gohugo.io/t/relpermalink-for-static/54599/5 "2025-05-02T07:07:45Z")

</div>

> [@davidsneighbour](#):
>
> directory to `assets/static` and then do `resources.Get "static/something.jpg"`

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).

---

<div class="post-metadata">

**Author:** ![gleicher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/gleicher/32/11543_2.png) [@gleicher](https://discourse.gohugo.io/u/gleicher)\
**Post date:** [May 2, 2025, 12:47pm UTC](https://discourse.gohugo.io/t/relpermalink-for-static/54599/6 "2025-05-02T12:47:37Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![gleicher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/gleicher/32/11543_2.png) [@gleicher](https://discourse.gohugo.io/u/gleicher)\
**Post date:** [May 2, 2025, 12:49pm UTC](https://discourse.gohugo.io/t/relpermalink-for-static/54599/7 "2025-05-02T12:49:17Z")

</div>

Thank you!  
That’s a great short-term fix.
