Hugo Framework and Gitlab Pages

One of the first ideas to have a website or blog is to use a CMS like Wordpress, Drupal or the good SPIP, all of these developed with PHP and require a database to function, a server or hosting.

One of the solutions that exist to avoid buying a hosting or server is to generate static sites with a tool like Jekyll or my favorite Hugo Framework, these combined with Gitlab Pages or Github Pages.

We already made a post to create a blog with Hugo Framework + Github Pages, this time we will make a small demo to use Hugo Framework + Gitlab Pages, using the default domain as and then we will customize the domain to our own.

Step 1: We started the Hugo Project Locally

After installing Hugo Framework, we can use the hugo command from a terminal to initialize the project.

1$ hugo new site --force

- We prepare the Website and Git files

1$ cd
2$ git init
3$ echo public > .gitignore
4$ git submodule add themes/theme_name
5$ echo 'theme = "theme_name"' >> config.toml
6$ hugo new posts/

- Gitlab Pages Requirements

Before uploading the project to a Gitlab repository, we edit the .gitmodules file to add relative URLs.

Gitlab uses HTTPS to get source code on shared runners, so:

 1## For a fork that belongs to the same group or user
 2$ vim .gitmodules
 3-- [submodule "themes/theme_name"]
 4-- path = themes/theme_name
 5-- url = ../../dev_name/theme_name.git ## New line
 7## For a project outside the group or user
 8$ vim .gitmodules
 9-- [submodule "themes/theme_name"]
10-- path = themes/theme_name
11-- url = ## New line
13## Update submodules
14$ git submodule update

- Gitlab CI

We create the .gitlab-ci.yml file to deploy the project when pushing to the repository, the content for this file would be the following:

 1$ vim .gitlab-ci.yml
 2-- image:
 4-- variables:
 5--   GIT_SUBMODULE_STRATEGY: recursive
 7-- test:
 8--   script:
 9--   - hugo
10--   except:
11--   - master
13-- pages:
14--   script:
15--   - hugo
16--   artifacts:
17--     paths:
18--     - public
19--   only:
20--   - master

- Gitlab Repository

To create the repository we must do it with the name where ¨user¨ is the Gitlab username, you can also create a group and use the group name for the name of repository

After creating the repository we add the code, after adding the URL to the project:

1$ git remote add origin
2$ git add .
3$ git commit -m 'Hugo gitlab page'
4$ git push origin master

- We verify the deployment in the repository

If everything went well we should have an output similar to the image, Repositorio -> CI/CD -> Pipelines.

Then we can check with the URL:

Step 2: Gitlab Custom Domain

With what has been done previously and if there was no problem we can customize the domain to one of our own choosing, for the example we will use the domain and

- Creating Domains

In Gitlab we can enter the Repository -> Settings -> Papes space and add the chosen domain and subdomain:

  • For

With these two steps completed we will have the repository and the subdomain with the user ready to work, in the case of the personal subdomain, the necessary records should be created in the DNS server.

- DNS Records and Gitlab Checks

For the root domain an A record must be created with the following data:

The A record for the root domain with the value, then a TXT record with the values provided by Gitlab Pages.

After creating the records we can verify from Gitlab:

For the subdomain a record CNAME must be created with the values provided by Gitlab Pages.

The CNAME record for the subdomain with the value "", then a TXT record with the values provided Gitlab Pages.

Clone repository

1$ git clone --recurse-submodules

Delete submodules

1$ git submodule deinit -f -- themes/theme_name
2$ rm -rf .git/modules/themes/themes_name
3$ git rm -f themes/themes_name
4$ git submodule status