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


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

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 }}

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


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