Hugo 命令速查手册

创建新网站

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 当前写法
hugo new project site-name

# 兼容写法
hugo new site site-name

# 强制创建到非空目录
hugo new project site-name --force

# 指定配置格式
hugo new project site-name --format yaml
hugo new project site-name --format json
hugo new project site-name --format toml

创建内容

1
2
3
4
5
6
7
8
# 使用 archetype 创建新文章(显式写 content 子命令,语义最清楚)
hugo new content posts/my-article.md

# 创建到子目录
hugo new content posts/category/my-article.md

# 指定内容类型
hugo new content --kind term posts/my-article.md

开发服务器

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 启动开发服务器(默认 http://localhost:1313)
hugo server

# 包含草稿文章
hugo server --buildDrafts
hugo server -D

# 指定端口
hugo server --port 8080
hugo server -p 8080

# 禁用 Fast Render(完整重建)
hugo server --disableFastRender

# 绑定到所有网络接口(局域网访问)
hugo server --bind 0.0.0.0

# 查看草稿和未来日期的文章
hugo server --buildDrafts --buildFuture
hugo server -D -F

# 开发服务器默认监听项目文件变化,无需额外参数

构建网站

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 构建到 public/ 目录
hugo

# 构建包含草稿
hugo --buildDrafts
hugo -D

# 删除目标目录中不属于本次构建的文件后构建
hugo --cleanDestinationDir

# 指定构建输出目录
hugo --destination /path/to/output
hugo -d /path/to/output

# 指定配置文件(--config 没有简写;-c 是 --contentDir 的简写,别混用)
hugo --config my-config.toml

# 指定主题
hugo --theme my-theme
hugo -t my-theme

# 指定 baseURL
hugo --baseURL https://example.com/
hugo -b https://example.com/

配置与查询

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 查看所有配置
hugo config

# 列出所有页面
hugo list all

# 列出所有草稿
hugo list drafts

# 列出所有过期页面
hugo list expired

# 列出所有未来发布页面
hugo list future

内容管理

1
2
3
4
5
6
# 清理 Hugo Module 文件缓存(只针对 Hugo Modules)
hugo mod clean

# 查看模块依赖和校验模块
hugo mod graph
hugo mod verify

实用选项

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 显示调试信息
hugo --logLevel debug

# 安静模式(减少输出;--quiet 没有简写)
hugo --quiet

# 显示版本信息
hugo version

# 显示帮助
hugo help

# 指定源目录
hugo --source /path/to/source
hugo -s /path/to/source

# 指定环境
hugo --environment production
hugo -e production

快捷操作

1
2
3
4
5
6
7
8
# 完整渲染模式启动开发服务器
hugo server --disableFastRender

# 创建并启动编辑
hugo new content posts/article.md && code content/posts/article.md

# 生产式构建(按项目约定决定是否包含未来日期内容)
hugo --minify --buildFuture --cleanDestinationDir

常见问题

1
2
3
4
5
# 查看所有页面及其状态
hugo list all

# 查看特定页面信息(rg 可替换为 grep)
hugo list all | rg "页面名称"

常用简写对照

简写全称
-D--buildDrafts
-F--buildFuture
-p--porthugo server 的旗标)
-d--destination
-t--theme
-c--contentDir
-b--baseURL
-s--source
-e--environment

--config--quiet 等没有简写;不要把 -c 当成 --config 使用(它是 --contentDir)。

简写和子命令会随 Hugo 版本演进。本文按本仓库要求的 Hugo Extended 版本线整理;在其他机器上以 hugo helphugo <command> --helphugo version 的实际输出为准。