Link to static file

How can I link to a file saved in static/?
The following generates the right file path but hugo server returns a 404 error:

[here's my link](/static/folder/file.txt)
1 Like

Try putting the file in static/static in that case.

It would just be /folder/file.txt

2 Likes

Sure, I should have tried that also, but my unix-minded (filesystem) approach was using the full path or the relative path without /
Thanks

It’s always better to have absolute links in case you host the side at a relative domain (like /blog).
You can create a shortcode (at layouts/shortcodes/link.html) to generate absolute links:

<a href="{{ .Page.Site.BaseUrl }}/{{ .Get 0 }}"/>
    {{ .Inner }}
</a>

And use it in the markdown like this:

{{% link <url> %}}Some Text{{% /link %}}

You can pass more options to the shortcode if you want to be more specific.
Also useful to have something similar for <img>.

3 Likes

A post was split to a new topic: Is this the right static dir?