Publication on GitHub pages and BaseURL

Hello,

I have recently started work on a Hugo website that I publish on GitHub pages at https://tuttu.github.io/StellarisAssets/. This is a project GitHub site so the last part StellarisAssets is mandatory in the URL.

I have set my baseURL to baseURL = 'https://tuttu.github.io/StellarisAssets/' and locally with Hugo server, everything renders fine. But when I publish on GitHub pages, all the link to my static content (CSS, JS, pictures…) are broken because they are in the form of https://tuttu.github.io/myCSS.css rahter than https://tuttu.github.io/StellarisAssets/myCSS.css.

With some help, I figured I could I could add {{ .Site.BaseURL }} before the relative links to all my static content to solve the issue. However, I feel like it’s not normal and I can’t understand why the site behaves like it does once published on GitHub pages. Anyone could explain it to me?

If interested, the source are located here: https://github.com/Tuttu/StellarisAssets
The theme I’m using is custom build from scratch and and example use of {{ .Site.BaseURL }} can be found here: https://github.com/Tuttu/StellarisAssets/blob/master/themes/StellarisTheme/layouts/partials/head.html

You have several choices:

  • set baseURL = "/" but all your internal links need to be relative (not the best…)
  • add relativeURLs = true but maybe other things will break, you have to check internal links

I prefer the second option :slight_smile:

Hmm, the https://tuttu.github.io/StellarisAssets/ is working, is it a cache issue of GitHub Pages?

(Good point I didn’t check…)

The live version is working because I have added {{ .Site.BaseURL }} to all the static URL. :slightly_smiling_face:

  • The path with leading slash like /css/style.css is the absolute path to the domain, it doesn’t work with sub path.
  • The path without a leading slash like css/style.css is the relative path to the current page’s URL.

You could use the built-in functions to build relative and absolute URLs which related to the baseURL, in order to avoid these problems.

2 Likes

Thanks @razon
I ended using relURL to build good URLs and it’s working like a charm. :slight_smile:

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.