How to create and deploy a Hugo site? Basic setup of Hugo with Hextra theme on Arch Linux and deployment on Cloudflare Pages
This article is for Linux. For Windows or MacOS check out my other articles.
Here I use Arch Linux btw. For other Linux distros, the way to install packages is different. Check out the installation guide for Linux on the official Hugo website. https://gohugo.io/installation/linux
Install git
sudo pacman -S git
git config --global init.defaultBranch main
git config --global user.name "your-user-name"
git config --global user.email "your-email"
- You can use an email like this: “123456789+your-user-name@users.noreply.github.com” (can be found in your Github settings)
Install go
sudo pacman -S go
Install github-cli
sudo pacman -S github-cli
gh auth login
gh auth statusto check login status
Install hugo
sudo pacman -S hugo
Github create repository: hugo--1
Create a new repository on Github: hugo--1 (public or private)
Create a new Hugo site
cd ~/workspace/github.com/your-user-name
git clone https://github.com/your-user-name/hugo--1`
cd hugo--1
hugo new site hugo--1 --format=yaml
mv hugo--1/* hugo--1/.* ./
rm -rf hugo--1
hugo mod init github.com/your-user-name/hugo--1
Github create repository: __fork__hextra--1
Create a new repository on Github: __fork__hextra--1 (public)
cd ~/workspace/github.com/your-user-name
git clone https://github.com/your-user-name/__fork__hextra--1`
Paste the content of .zip file from hextra
git add .
git commit -m "basic setup"
git push origin main
Github edit go.mod: module github.com/your-user-name/__fork__hextra--1
[delete] module github.com/imfing/hextra
[add] module github.com/your-user-name/__fork__hextra--1Add Hextra theme to the Hugo site
cd ~/workspace/github.com/your-user-name/hugo--1
hugo mod get github.com/your-user-name/__fork__hextra--1
nano hugo.yaml or use VSCode to edit
Add
module:
imports:
- path: github.com/your-user-name/__fork__hextra--1Add content
hugo new content/_index.md
hugo new content/blog/_index.md
Check site render
hugo server -D --disableFastRender
Ctrl C to stop the server
Edit hugo.yaml
nano hugo.yaml or use VSCode to edit
Edit
baseURL: https://www.your-domain-name.com
languageCode: zh-TW
title: your-website-namePush to Github
ls
tree -a
touch archetypes/.gitkeep assets/.gitkeep content/.gitkeep data/.gitkeep i18n/.gitkeep layouts/.gitkeep public/.gitkeep static/.gitkeep themes/.gitkeeptree -a
git add .
git commit -m "basic setup"
git push origin main
Deploy to Cloudflare Pages
Pages
| Configuration | Value |
|---|---|
| Production branch | main |
| Build command | hugo --gc --minify |
| Build directory | public |
Environment variables (advanced): HUGO_VERSION: 0.0.0
https://developers.cloudflare.com/pages/framework-guides/deploy-a-hugo-site