Hugo + Stack + GitHub Pages Blog Setup Guide
A complete guide to building a personal blog with Hugo + Stack theme and deploying it to GitHub Pages.
This guide covers both new Stack (v4.x, split .toml config format) and legacy (v3.x, single hugo.yaml) configuration differences, with annotations where key differences exist.
Environment Setup
Install Git
- Go to the Git website to download and install: https://git-scm.com/downloads
- Use all default options during installation
Install Hugo (Extended Version)
- Go to Hugo GitHub Releases: https://github.com/gohugoio/hugo/releases
- Choose the extended version (marked with
extended) โ the Stack theme requires extended SCSS compilation support - Windows users: download
hugo_extended_xxx_windows-amd64.zipand extracthugo.exe
This guide was written using Hugo v0.161.1 and Stack theme v4.0.2.
GitHub Account
- Register a GitHub account: https://github.com
- It’s recommended to enable two-factor authentication (2FA) โ you can install the Authenticator 2FA Client plugin in Edge
Create a Hugo Site
Initialize the Project
Open a terminal in the directory where hugo.exe is located (type cmd or powershell in the address bar) and run:
|
|
Generated file structure:
|
|
Test the Default Site
|
|
Visit http://localhost:1313/ in your browser. The page will be basic (no theme). Press Ctrl + C to stop the server.
Configure the Stack Theme
Download the Theme
- Go to the Stack theme GitHub: https://github.com/CaiJimmy/hugo-theme-stack
- Download the latest Release archive (or click “Download ZIP”)
- Extract to the site’s
themes/directory
|
|
Configure Theme Files โ Critical Step
This is the step where errors are most likely to occur. The new Stack (v4.x) and legacy (v3.x) have completely different file structures:
| Comparison | Legacy Stack (v3.x) | New Stack (v4.x) |
|---|---|---|
| Example site folder name | exampleSite/ |
demo/ |
| Config files | Single hugo.yaml |
Multiple .toml files in config/_default/ |
| Theme reference | theme: hugo-theme-stack |
[[module.imports]] (Hugo Modules) |
New Version (v4.x) Steps:
Step 1: Copy Configuration Files
|
|
After copying, config/_default/ contains 6 config files:
| File | Purpose |
|---|---|
hugo.toml |
Base config (baseURL, title, pagination, permalinks, etc.) |
languages.toml |
Multilingual configuration |
markup.toml |
Markdown rendering config (code highlighting, TOC, etc.) |
menu.toml |
Menu config (navigation bar, social links) |
params.toml |
Theme parameters (sidebar, comments, widgets, etc.) |
related.toml |
Related content recommendation config |
Step 2: Change Theme Reference Method
Open config/_default/hugo.toml, find:
|
|
Replace with:
|
|
This traditional method doesn’t require Go environment or Hugo Modules, making it simpler and consistent with this guide.
Step 3: Handle Root hugo.toml Conflict
The root hugo.toml and config/_default/hugo.toml will conflict. Back up or delete the root file:
|
|
Step 4: Copy Example Content
|
|
Step 5: Copy Avatar and Static Assets
|
|
Legacy Version (v3.x) Steps:
- Enter the theme’s
exampleSite/folder - Copy the
contentfolder andhugo.yamlto the site root - Delete the root
hugo.toml(since you now havehugo.yaml) - Confirm that the
themefield inhugo.yamlmatches the theme folder name (version number removal recommended)
Verify by Starting
|
|
Visit http://localhost:1313/ in your browser. You should now see the complete Stack theme (with sidebar, search, example articles, etc.).
If the page is incomplete, check the terminal for WARN messages (e.g., “Search page not found”, “Archives page not found”). This is usually because example content wasn’t copied.
Custom Configuration
Basic Information
Edit config/_default/hugo.toml (new version) or hugo.yaml (legacy):
|
|
If your primary language is Chinese, it’s recommended to set:
|
|
Sidebar
Edit config/_default/params.toml (new version) or the params.sidebar section in hugo.yaml:
|
|
- Place the avatar image at
assets/img/avatar.png - Choose emojis from emojiall.com
Social Links
Edit config/_default/menu.toml (new version) or the menu.social section in hugo.yaml:
|
|
Icon names reference: Tabler Icons (use brand-xxx format).
Comment System
Stack supports multiple comment systems. Here’s an example using utterances (based on GitHub Issues, no extra registration needed):
|
|
For more comment system configurations, see the theme documentation: https://stack.jimmycai.com/config/comments
Footer
|
|
Creating Articles
Article Structure
The Stack theme recommends each article in its own folder with index.md and image assets:
|
|
Generated directory structure:
|
|
Article Front Matter Example
|
|
Deploy to GitHub Pages
Create a GitHub Repository
- Log in to GitHub, click New repository
- Repository name:
your-username.github.io(must match exactly) - Select Public (GitHub Pages free tier requires public)
- Do not check “Add a README file”
Manual Deployment
|
|
After pushing successfully, visit https://your-username.github.io/ to see your blog (the first time may take 1-2 minutes).
Automatic Deployment (GitHub Actions)
Manually building and pushing every time is tedious. Use GitHub Actions to automatically build and deploy when you push code.
Step 1: Create a Source Repository
In addition to the username.github.io deployment repository, create a source repository (e.g., myblog) and push the entire Hugo project to it:
|
|
Step 2: Create GitHub Actions Workflow
Create .github/workflows/deploy.yml in the site root:
|
|
Step 3: Configure GitHub Token
- Go to GitHub โ Settings โ Developer settings โ Personal access tokens โ Tokens (classic)
- Generate a new Token with
repoandworkflowpermissions - Copy the generated Token
- Go to your source repository โ Settings โ Secrets and variables โ Actions โ New repository secret
- Name:
PERSONAL_TOKEN, Value: paste the Token
From now on, every git push to the source repository’s main branch will trigger GitHub Actions to automatically build and deploy to username.github.io.
Tip: Enable Automatic lastmod Add the following to
config/_default/hugo.toml(new version) orhugo.yaml(legacy):
1 2 3enableGitInfo = true [frontmatter] lastmod = [":git", ":fileModTime"]This will automatically display the Git commit time as the last modified time for articles. This requires
fetch-depth: 0in the GitHub Actions checkout step (already included in the configuration above).
FAQ
Q1: Page is blank/incomplete after starting?
Check whether you copied the demo’s content folder. Missing example pages (search, archives, etc.) will cause the theme to display incompletely.
Q2: hugo server throws “Theme not found” error?
- New version: Check that
theme = "xxx"inconfig/_default/hugo.tomlmatches the folder name underthemes/ - Legacy: Check the
themefield inhugo.yaml
Q3: Root hugo.toml conflicts with config/_default/hugo.toml?
Delete or back up the root hugo.toml. Hugo will prioritize config files under config/_default/.
Q4: Push to GitHub fails?
This may be a network issue. Try removing the proxy:
|
|
Q5: What is the new [[module.imports]]?
The new Stack uses Hugo Modules (Go modules) to import the theme by default, which requires a Go environment. If you don’t want to deal with Go, simply switch to the traditional theme = "theme-folder-name" method.
Q6: Blog styles are broken after deployment?
Check that baseURL is correctly set to https://your-username.github.io/ (note the trailing /). An incorrect baseURL will cause CSS/JS resources to fail to load.