How to create and deploy a Hugo site? Basic setup of Hugo with Hextra theme on Linux and deployment on Cloudflare Pages
Install git, go, and dart-sass
In this article Arch Linux is used. For other Linux distros check out the installation guide on the official Hugo website. https://gohugo.io/installation/linux
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: “[email protected]” (can be found in your Github settings)
Go
sudo pacman -S go
Dart Sass
sudo pacman -S dart-sass
Install github-cli
sudo pacman -S github-cli
gh auth login
(gh auth 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 fork: __fork__hextra-0.9.7
Create a fork of Hextra on Github (public)
Add Hextra theme to the Hugo site
Github edit go.mod: module github.com/your-user-name/__fork__hextra-0.9.7
hugo mod get github.com/your-user-name/__fork__hextra-0.9.7
nano hugo.yaml
or use VSCode to edit
Add
module:
imports:
- path: github.com/your-user-name/__fork__hextra-0.9.7
Add 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-name
Push to Github
ls
tree -a
touch archetypes/.gitkeep assets/.gitkeep content/.gitkeep data/.gitkeep i18n/.gitkeep layouts/.gitkeep public/.gitkeep static/.gitkeep themes/.gitkeep
tree -a
git add .
(git status
)
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