Hugo 命令速查手册

创建新网站

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 创建新项目(推荐)
hugo new project site-name

# 旧写法(仍然可用)
hugo new site site-name

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

# 指定配置格式
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 创建新文章
hugo new posts/my-article.md

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

# 指定内容类型
hugo new --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
23
24
# 启动开发服务器(默认 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

# 监听文件变化
hugo server --watch
hugo server -w

构建网站

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

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

# 清理构建缓存后构建
hugo --cleanDestinationDir

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

# 指定配置文件
hugo --config my-config.toml
hugo -c 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
7
8
# 删除构建缓存和生成的文件
hugo --cleanDestinationDir

# 删除资源缓存
rm -rf resources/

# 删除 public 目录
rm -rf public/

实用选项

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 显示详细输出
hugo --verbose
hugo -v

# 显示调试信息
hugo --debug

# 安静模式(减少输出)
hugo --quiet
hugo -q

# 显示版本信息
hugo version

# 显示帮助
hugo help

# 指定内容目录
hugo --contentDir /path/to/content
hugo -c /path/to/content

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

# 指定布局目录
hugo --layoutDir /path/to/layouts
hugo -l /path/to/layouts

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

快捷操作

1
2
3
4
5
6
7
8
# 清理并重新启动开发服务器
rm -rf public resources && hugo server --disableFastRender

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

# 构建并测试
hugo && hugo server

常见问题

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

# 检查页面是否被构建
hugo server | grep "Total in"

# 查看特定页面信息
hugo list all | grep "页面名称"

常用简写对照

简写 全称
-D --buildDrafts
-F --buildFuture
-p --port
-d --destination
-t --theme
-c --config--contentDir
-v --verbose
-q --quiet
-w --watch
-b --baseURL
-s --source
-l --layoutDir
-e --environment