Hugo 实战小技巧集合

2026年1月8日 · 35 字 · 1 分钟

在折腾 Hugo 的过程中,我记录了一些实用的小技巧,方便以后查阅,也给同样使用 Hugo 的你一些参考。

1. 为开发和生产使用不同配置

可以通过 --config 指定不同配置文件,例如:

1hugo server --config hugo.toml,config-dev.toml

2. 使用 mainSections 控制首页和归档

在配置中设置:

1[params]
2mainSections = ["posts"]

可以确保首页、归档等只展示 posts 目录下的文章。

3. 使用 Page Bundle 管理图片

为某篇文章创建同名目录,例如:

1content/posts/my-post/index.md
2static/images/...

然后在文章中直接使用相对路径插图,便于迁移和管理。