Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double-slashes in URLs and add trailing slash where appropriate #257

Merged
merged 4 commits into from
Jul 26, 2021

Conversation

jtc
Copy link
Contributor

@jtc jtc commented Jul 25, 2021

Many links on the site, including nav, are constructed like href="{{ .Site.BaseURL }}/page". As the config baseURL is https://uqcs.org/, this results in a double slash on many links, e.g. renders to href="https://uqcs.org//about". This double-slash also shows in the browser status bar on hover, so looks a bit dodgy.

Best practice now (1) (2) seems to be to use the absURL or relURL functions to construct such links, taking care of the required slashes regardless of baseURL having a trailing slash or not and other environmental considerations. I have gone with relURL in this PR. The site previously had a mix of absolute and relative URLs anyway, so this brings them all to relative.

However, should reviewers prefer absolute URLs, there are two options:

  1. canonifyURLs can be added and set to true in config, which will change all URLs on the site, even previously relative, to absolute, and allows easy changing back should there be a future desire to do so.
  2. All relURLs in the PR can simply be changed to absURL, therefore only affecting links that previously used baseURL.

While making this PR, I also noticed that despite links such as https://uqcs.org/about, these would be 301 redirected to https://uqcs.org/about/ (trailing slash). As Hugo's default pretty URLs mode creates directories for each page, it does not support removing the trailing slash (3) (4). Therefore, I've added the trailing slash to such internal links so that we link straight to the canonical page.

jtc added 4 commits July 25, 2021 17:18
Change non-shortcode templates to use the relURL function instead of
concatenating off {{ .Site.BaseURL }}, fixing the double-slash issue
Add a relURL shortcode and use this on content pages, instead of
the baseurl shortcode which is now deleted. This fixes double-slash
issues.
where not already present
Change baseurl key to baseURL in config file. Technically, either works,
but this follows the Hugo docs and is included in a bigger PR anyway so
why not?
@jtc jtc mentioned this pull request Jul 25, 2021
Copy link
Member

@jdcaperon jdcaperon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -1,5 +1,5 @@
# Site settings
baseurl = "https://uqcs.org/"
baseURL = "https://uqcs.org/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of a shame that Hugo breaks from the standard for not capitalising acronyms longer than two chars.

baseURL is correct in the Hugo sphere

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think by shame here Jack means "breath of fresh air"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

baseUrl is superior 👀

@nicklambourne nicklambourne merged commit 95bf3a5 into UQComputingSociety:master Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants