host-on-gitlab-pages.md - hugo - [fork] hugo port for 9front
(HTM) git clone https://git.drkhsh.at/hugo.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
host-on-gitlab-pages.md (3574B)
---
1 ---
2 title: Host on GitLab Pages
3 description: Host your site on GitLab Pages.
4 categories: []
5 keywords: []
6 aliases: [/hosting-and-deployment/hosting-on-gitlab/]
7 ---
8
9 ## Assumptions
10
11 - Working familiarity with Git for version control
12 - Completion of the Hugo [Quick Start]
13 - A [GitLab account](https://gitlab.com/users/sign_in)
14 - A Hugo website on your local machine that you are ready to publish
15
16 ## BaseURL
17
18 The `baseURL` in your [site configuration](/configuration/) must reflect the full URL of your GitLab pages repository if you are using the default GitLab Pages URL (e.g., `https://<YourUsername>.gitlab.io/<your-hugo-site>/`) and not a custom domain.
19
20 ## Configure GitLab CI/CD
21
22 Define your [CI/CD](g) jobs by creating a `.gitlab-ci.yml` file in the root of your project.
23
24 ```yaml {file=".gitlab-ci.yml" copy=true}
25 variables:
26 DART_SASS_VERSION: 1.89.2
27 GIT_DEPTH: 0
28 GIT_STRATEGY: clone
29 GIT_SUBMODULE_STRATEGY: recursive
30 HUGO_VERSION: 0.147.9
31 NODE_VERSION: 22.x
32 TZ: America/Los_Angeles
33 image:
34 name: golang:1.24.2-bookworm
35
36 pages:
37 stage: deploy
38 script:
39 # Install brotli
40 - apt-get update
41 - apt-get install -y brotli
42 # Install Dart Sass
43 - curl -LJO https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz
44 - tar -xf dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz
45 - cp -r dart-sass/ /usr/local/bin
46 - rm -rf dart-sass*
47 - export PATH=/usr/local/bin/dart-sass:$PATH
48 # Install Hugo
49 - curl -LJO https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb
50 - apt-get install -y ./hugo_extended_${HUGO_VERSION}_linux-amd64.deb
51 - rm hugo_extended_${HUGO_VERSION}_linux-amd64.deb
52 # Install Node.js
53 - curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION} | bash -
54 - apt-get install -y nodejs
55 # Install Node.js dependencies
56 - "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
57 # Configure Git
58 - git config core.quotepath false
59 # Build
60 - hugo --gc --minify --baseURL ${CI_PAGES_URL}
61 # Compress
62 - find public -type f -regex '.*\.\(css\|html\|js\|txt\|xml\)$' -exec gzip -f -k {} \;
63 - find public -type f -regex '.*\.\(css\|html\|js\|txt\|xml\)$' -exec brotli -f -k {} \;
64 artifacts:
65 paths:
66 - public
67 rules:
68 - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
69 ```
70
71 ## Push your Hugo website to GitLab
72
73 Next, create a new repository on GitLab. It is *not* necessary to make the repository public. In addition, you might want to add `/public` to your .gitignore file, as there is no need to push compiled assets to GitLab or keep your output website in version control.
74
75 ```sh
76 # initialize new git repository
77 git init
78
79 # add /public directory to our .gitignore file
80 echo "/public" >> .gitignore
81
82 # commit and push code to master branch
83 git add .
84 git commit -m "Initial commit"
85 git remote add origin https://gitlab.com/YourUsername/your-hugo-site.git
86 git push -u origin master
87 ```
88
89 ## Wait for your page to build
90
91 That's it! You can now follow the CI agent building your page at `https://gitlab.com/<YourUsername>/<your-hugo-site>/pipelines`.
92
93 After the build has passed, your new website is available at `https://<YourUsername>.gitlab.io/<your-hugo-site>/`.
94
95 ## Next steps
96
97 GitLab supports using custom CNAME's and TLS certificates. For more details on GitLab Pages, see the [GitLab Pages setup documentation](https://about.gitlab.com/2016/04/07/gitlab-pages-setup/).
98
99 [Quick Start]: /getting-started/quick-start/