为什么要用 Hugo?#
Hugo 是目前最快的静态网站生成器之一,特点:
- ⚡ 构建速度极快(1000篇文章只需1秒)
- 🎨 丰富的主题生态
- 🆓 完全免费开源
- 🚀 部署简单
安装 Hugo#
Windows#
1
| choco install hugo-extended
|
macOS#
验证安装#
创建博客#
1
2
3
4
5
6
| # 创建新站点
hugo new site my-blog
cd my-blog
# 下载主题(以 PaperMod 为例)
git submodule add https://github.com/adityatelange/hugo-PaperMod.git themes/PaperMod
|
配置文件#
编辑 hugo.toml:
1
2
3
4
5
6
7
8
| baseURL = 'https://你的域名/'
languageCode = 'zh-cn'
title = '我的博客'
theme = 'PaperMod'
[params]
author = '你的名字'
defaultTheme = 'auto'
|
写文章#
1
2
| # 创建新文章
hugo new content posts/my-first-post.md
|
然后编辑 content/posts/my-first-post.md:
1
2
3
4
5
6
7
8
| ---
title: "我的第一篇文章"
date: 2026-06-16
tags: ["入门"]
draft: false
---
正文内容...
|
本地预览#
浏览器访问 http://localhost:1313 即可预览。
构建与部署#
1
2
3
4
| # 构建静态文件
hugo --minify
# public/ 目录就是生成的静态文件
|
部署到 GitHub Pages#
这个博客使用 GitHub Actions 自动构建和部署源码:
- 创建 GitHub 仓库,并把 Hugo 源码推送到默认分支
- 在
.github/workflows/deploy.yml 中配置 Hugo 构建、Pages Artifact 上传和部署步骤 - 在仓库
Settings → Pages 中将部署来源设为 GitHub Actions - 后续每次推送源码,工作流会运行
hugo --minify --gc 并发布 public/
如果 PaperMod 以 Git submodule 管理,需要在 checkout 步骤启用 submodules: recursive;如果主题作为普通目录提交,则保持当前配置即可。
这就是搭建一个 Hugo 博客的完整流程,整个过程不到10分钟!