This will be very specific to the Hugo Academic theme, so apologies if I’m posting this in the wrong place.
I’ve made an academic website using the Hugo Academic theme (which I’m very happy with). Unfortunately, the ‘cite’ feature for my publications isn’t functioning: the cite box comes up but it can’t seem to find the .bib file (Error: 404 Not Found).
I am using Hugo v0.56.3.
I wonder if it’s related to the baseURL setup of my site (indeed, the feature works fine when running hugo server and going to localhost:1313): At first I had difficulty getting my site and its internal links to load, which was eventually fixed by entering the following into config.toml:
baseurl = ""
relativeURLs=true
CanonifyURLs=true
and when I build the site with Hugo I change the baseURL:
hugo --baseURL=dept.uni.ac.uk/~user/
For my institution I need to change the name of the public folder to public_html, and I then drop it with Filezilla into the root folder of my local unix account hosted by the university.
Hello the Academic theme already uses relative links in its templates. Remove relativeURLs=true from the config and see if that fixes the missing citation resource.
Also to set the name of the public directory to what you need please add the following to the project’s config: publishDir = "public_html"
Furthermore note that you have to set a baseURL so that your project and its assets are published properly.
I’ve just tried putting baseURL = "dept.uni.ac.uk/~user/" into the config.toml (question: isn’t doing this functionally equivalent to putting the flag --baseURL =… when I run Hugo, as I mentioned I was doing? If so, isn’t it better style to do that, so that the choice of the baseURL is chosen when building the site rather than being in the site’s code?).
I tried deleting relativeURLs=true. But then my site doesn’t display properly, everything is unformatted. Perhaps the issue is with the format of how I’m choosing my baseURL?
If there’s no obvious fix you can see, maybe I can upload my site code later. Many thanks for your help!
Yes it is. But why typing it all the time? Entering it into the config saves time.
Well, I don’t type it, I just use the terminal’s history. But whatever.
As to the main issue, I get a minimal working example as follows:
Straight from the Hugo Academic Theme example site (where, without modification, the citation feature works), I make only the following change to the config file:
I then run hugo server, and on localhost:1313/~user I scroll to the Featured Publications. Pressing the Cite button there yields the same error.
As mentioned, when I remove relativeURLs my online site doesn’t seem to display properly. It works ok for hugo server, but the bug above happens regardless of whether I add that line or not.
As I said above it already constructs relative URLs directly in the templates so you can most certainly do without relativeURLs
Now I am not sure about that tilde ~ in your baseURL. There has always been some kind of URL sanitization in Hugo. If the tilde is not allowed it may be the culprit.
Also make sure to enter the https:// or http:// protocol in your baseURL
Please try setting a baseURL without the tilde locally so that you can test it out and let us know.
Making progress…: Changing the tilde didn’t seem to make a difference. But I’ve now removed canonicalURLs and relativeURLs, added https://www. at the start of my previous baseURL, and the page now displays correctly, with the cite feature working.
Unfortunately that breaks the internal links of the site that I’ve made myself (this may be why I put relativeURLs on in the first place - I’m very new to many aspects of building sites, so I think this will be an extremely stupid error here…).
Suppose I want a link to a static file on a page, located in root/static/photos/photo.jpg. I’ve put the following in Markdown:
[link to photo](/photos/photo.jpg)
Similarly, if I want to link to another page of my own site (of the form baseURL/page), I’ve used code like:
[link to page](/page/)
But now that I’ve removed relativeURLs, internal links now omit the /~user part of the address (for example, the first link above now directs to www.dept.uni.ac.uk/photos/photo.jpg rather than www.dept.uni.ac.uk/photos/~user/photo.jpg). I have no idea why. Of course, it would be ad hoc and non-adaptable to add /~user into all of my links. Do you know the solution to this?
Since your website will be published in a subdirectory you need to remove the first forward slash from manual internal links because this slash makes the URL point to the host root and Hugo will not be able to generate the correct links to your project’s assets.
So the above needs to be changed to:
[link to photo](photos/photo.jpg)
[link to page](page/)
Ahha! I thought I had tried that, but before I thought it hadn’t changed anything since surprisingly it seems to only change when running Hugo server again (I hadn’t expected that for just altering a link).
I’m still having troubles with links when they’re not on the homepage. For example, what if I want to link to photos/photo.jpg from a Markdown file on a different page? So suppose I was on a page
baseURL/misc/stuff
and I put something in Markdown like
[link to photo](photos/photo.jpg)
What I really want is for the link to go to baseURL/photos/photo.jpg, rather than what it currently does (baseURL/misc/stuff/photos/photo.jpg). Is there a replacement for / which returns first to the subdirectory specified by the baseURL, rather than pointing to the root?
Edit1: one other thing, the above code also opens the links in new tabs, which isn’t what I want for internal links of my site. Apologies for this going off the original topic into my ignorance of how links work.
Edit2: I see that I can just use …/…/, for example, to go up two subdirectories to get where I want. Perhaps that’s the best (only?) option.
I think that your best bet instead of creating these links in Markdown is to use a ref or relref shortcode.
Also note that :
hrefTargetBlank
default: false
Blackfriday flag: HTML_HREF_TARGET_BLANK
Purpose: true opens external linksabsolute links in a new window or tab. While the target="_blank" attribute is typically used for external links, Blackfriday does that for all absolute links (ref). One needs to make note of this if they use absolute links throughout, for internal links too (for example, by setting canonifyURLs to true or via absURL ).
Thanks again for your help. As you say, it looks like I need to read up on organisation and work out how to work with these basic features. It is very annoying to me that I can’t just refer to my baseURL with /. So many workings of these things seem ad hoc to me (or to be missing obvious features).
Whenever I change one thing, it always seems to break another. For example, I have no idea why an internal link like
[link](page/)
would now decide to open a new tab, even with hrefTargetBlank = true (by the way, this seems to be true by default from the config I got from the Academic Theme). When I had relativeURLs = true and used [link](/page/), this didn’t happen.
Thanks. I went into the code of what a relative link is (because BlackFriday shouldn’t open such links in new tabs). For some reason, page/ wouldn’t count, but anything starting with a ./ or ../ would. I presume that ./ just means “current directory”, so the best workaround seems to be to use ./page/.
I don’t know the justification for that. And I don’t know the justification of why there’s no replacement for / when your site isn’t at the root. Maybe I will find out from reading the Page Bundles.