Link To Static Files
Documentation Estimated reading time: ~1 minutes
(Examples use a file at /static/path/to/image.jpg
)
There’s a limitation with the way links are created in markdown. In order to link to static files in content files, we need to either:
Write a path relative to the current directory, with
../
and the like, so a file atcontent/section/subsection/page.md
would need../../../path/to/image.jpg
Prefix the path with a leading
/
, which causes the path to resolve toexample.com/path/to/image.jpg
The first is a pain to have to do, and the second only works if the baseURL
of your Hugo site is example.com
. A site at example.com/subdir/
will still resolve the link to example.com/path/to/image.jpg
, which won’t exist.
To get around this limitation (at least until it gets implemented in Hugo), BluestNight includes a shortcode called static
that will correctly resolve links to static files according to the site’s baseURL
. The syntax is similar to the ref
and relref
shortcodes:

[Link text]({{< static "other/static/folder/file.txt" >}})
Example output, using a baseURL
of http://example.com/subdir/
:
