Beginner question: missing CSS or wrong baseUrl on GitLab Pages

I try to deploy a simple blog using Hugo and GitLab Pages.

I’ve done everything according to the “Hosting on Gitlab” tutorial and tried the Gitlab approach (i.e. fork an existing project and tweak it).

Everytime I encounter this unwanted behaviour:

  1. when I leave baseUrl empty ("") I’ve got CSS working on the main page, but the links to the posts are broken or CSS doesn’t work on other pages
  2. when I specify baseUrl according to the gitlab pages address: https://username.gitlab.io/project-name all links on the site work fine but CSS is missing for the whole site.

I don’t have this problem when I test the site locally using hugo server command.

This is link to my GitLab repo.

I am trying to implement Minos theme.

Here is my hugo env output:

Hugo Static Site Generator v0.51/extended linux/amd64 BuildDate: unknown
GOOS="linux"
GOARCH="amd64"
GOVERSION="go1.11.2"

Thank you in advance for any hints how to fix that.

Did you try baseURL with and without a trailing slash?

baseURL: https://username.gitlab.io/project-name

or

baseURL: https://username.gitlab.io/project-name/

Reason, no slash in hugo-theme-minos/head.html at master · carsonip/hugo-theme-minos · GitHub, line 15…

Not sure if this will make a difference, but I see the CSS links are build with .Site.BaseURL vs absURL.

Try overriding the theme’s head.html. So copy themes/minos/layouts/partials/head.html and paste it at layouts/partials/head.html, then make these changes on lines 12-15:

<link href="{{ "webfonts/ptserif/main.css" | absURL }}" rel='stylesheet' type='text/css'>
<link href="{{ "webfonts/source-code-pro/main.css" | absURL }}" rel="stylesheet" type="text/css">

<link rel="stylesheet" href="{{ "css/style.css" | absURL }}">

Or, you could try what @nfriedli mentioned.

@nfriedli I added the slash and now it works. Thanks a lot!

1 Like

@zwbetz Yes, slash solution worked, but thank you anyway – I will keep your solution in mind since I am learning Hugo and for sure will encounter other problems in the future. Thanks!

Created a GH issue for this:

1 Like