# Publication on GitHub pages and BaseURL

**URL:** <https://discourse.gohugo.io/t/publication-on-github-pages-and-baseurl/43631>\
**Category:** support\
**Created:** [March 27, 2023, 2:04pm UTC](https://discourse.gohugo.io/t/publication-on-github-pages-and-baseurl/43631 "2023-03-27T14:04:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tuttu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tuttu/32/19049_2.png) [@Tuttu](https://discourse.gohugo.io/u/Tuttu)\
**Post date:** [March 27, 2023, 2:04pm UTC](https://discourse.gohugo.io/t/publication-on-github-pages-and-baseurl/43631/1 "2023-03-27T14:04:03Z")

</div>

Hello,

I have recently started work on a Hugo website that I publish on GitHub pages at [https://tuttu.github.io/StellarisAssets/](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](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](https://github.com/Tuttu/StellarisAssets/blob/master/themes/StellarisTheme/layouts/partials/head.html)

---

<div class="post-metadata">

**Author:** ![antoinentl](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/antoinentl/32/12914_2.png) [@antoinentl](https://discourse.gohugo.io/u/antoinentl)\
**Post date:** [March 27, 2023, 2:55pm UTC](https://discourse.gohugo.io/t/publication-on-github-pages-and-baseurl/43631/2 "2023-03-27T14:55:03Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![razon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/razon/32/14882_2.png) [@razon](https://discourse.gohugo.io/u/razon)\
**Post date:** [March 27, 2023, 2:57pm UTC](https://discourse.gohugo.io/t/publication-on-github-pages-and-baseurl/43631/3 "2023-03-27T14:57:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![antoinentl](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/antoinentl/32/12914_2.png) [@antoinentl](https://discourse.gohugo.io/u/antoinentl)\
**Post date:** [March 27, 2023, 3:01pm UTC](https://discourse.gohugo.io/t/publication-on-github-pages-and-baseurl/43631/4 "2023-03-27T15:01:38Z")

</div>

(Good point I didn’t check…)

---

<div class="post-metadata">

**Author:** ![Tuttu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tuttu/32/19049_2.png) [@Tuttu](https://discourse.gohugo.io/u/Tuttu)\
**Post date:** [March 27, 2023, 4:14pm UTC](https://discourse.gohugo.io/t/publication-on-github-pages-and-baseurl/43631/5 "2023-03-27T16:14:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![razon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/razon/32/14882_2.png) [@razon](https://discourse.gohugo.io/u/razon)\
**Post date:** [March 27, 2023, 4:33pm UTC](https://discourse.gohugo.io/t/publication-on-github-pages-and-baseurl/43631/6 "2023-03-27T16:33:03Z")

</div>

- 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.

- [https://gohugo.io/functions/relurl/](https://gohugo.io/functions/relurl/)
- [absURL | Hugo](https://gohugo.io/functions/absurl/)

---

<div class="post-metadata">

**Author:** ![Tuttu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/tuttu/32/19049_2.png) [@Tuttu](https://discourse.gohugo.io/u/Tuttu)\
**Post date:** [March 27, 2023, 6:49pm UTC](https://discourse.gohugo.io/t/publication-on-github-pages-and-baseurl/43631/7 "2023-03-27T18:49:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [March 29, 2023, 6:50pm UTC](https://discourse.gohugo.io/t/publication-on-github-pages-and-baseurl/43631/8 "2023-03-29T18:50:51Z")

</div>

Closed on March 29, 2023, 6:50pm UTC

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