I have a documents page (content/documents.md
→ /documents
) where I want to link some static files. I put some files into static/documents
, which get put conveniently into /documents
by Hugo, so I can just use relative links in documents.md
, like:
[Awesome Document](Awesome%20Document.pdf)
It seemed to work well, until someone told me they get a 404 when they try to download the documents. At first, I didn’t understand, because it worked for me, but then I realized, they are clicking the links in the page’s preview on the index page! There, because the URLs are relative, web browsers try to access the file at /Awesome%20Document.pdf
instead of /documents/Awesome%20Documents.pdf
. I was surprised because I kind of expected Hugo to deal with this relative URL conondrum for me – while creating absolute links, like:
[Awesome Document](/documents/Awesome%20Document.pdf)
… would be possible, but then in case I’d put the entire site into a subdirectory and set a new baseURL
, all links would be broken. To be honest, I expected Hugo to allow me the convenience of relative links in my source files, but resolve them and create static links upon building the HTML site. In my understanding, canonifyURLs = true
would do exactly that. But in reality, it doesn’t do anything, my document links stay relative, and the feature is being marked as deprecated anyway. Maybe it would still work for other type of content, but not for static files.
Which is the supported, elegant, idiomatic way of doing this in Hugo? To avoid absolute links in Markdown, but still getting static, or calculated relative links in the published HTML?