发布日期: 2026-09-28
版本号: v0.167.0

本次 Hugo 版本更新主要包括:支持部分模板的相对路径引用,即以 ./ 或 ../ 开头的 partial 名称会相对调用方所在目录解析,便于编写可独立移动的模板树,但仅限 partial 内部使用,解析出 partials 目录之外会报错;section、taxonomy 和 term 页面现在也支持 slug 前置参数,并可向下级页面级联,对多语言站点尤其有用,例如 content/help/_index.es.md 设置 slug: ayuda 后会生成 /es/ayuda/ 及其子页面路径。其他改进还有新增 build.cleanDestinationDir 配置,支持 keepFiles/keepDirs Glob 模式,hugo 现在可以没有配置文件直接构建,eq、where、in 及集合函数支持精确数值比较,自动摘要不再截断在未闭合的列表或引用块内部。 安全方面包含多项加固修复,均无已知被利用的情况,但如使用不可信主题或模块建议升级:Sass 导入和 ESBuild 解析现在由 Hugo 自己处理并限制在 security.allowRead 允许的读取路径内,防止主题通过导入或符号链接读取项目外文件;修复了嵌套挂载点父级符号链接目录可能暴露模块外文件的问题;以及目录 TOC 中显式标题 ID 未转义导致的属性注入问题。 注意事项:默认 baseURL 从空字符串改为 https://example.org/,依赖空默认值生成相对 URL 的站点需显式设置;根级 cleanDestinationDir 配置已废弃,改用 build.cleanDestinationDir.enable,发布目录中的 .git 文件默认不再被清理;数值比较逻辑统一后 eq 1 1.0 现在返回 true;用户自定义表格渲染钩子优先于内置版本;自动摘要可能因容器闭合而变长,部分页面摘要内容可能变化。 修复的问题包括:Go 1.26 在 Fedora 44 Beta 上的构建失败、带旋转的 smartcrop 处理、不同数值类型切片的 union 操作、同目录多文件批量变更时页面内容过期,以及集成测试和 CI 脚本问题。此外还更新了多项依赖库、增加了 strings.FirstLower 函数、优化了模板格式化和部分性能,并将发布镜像升级到 Go 1.27.1。

更新内容 (中文)

本次发布带来了相对 partial 引用、分支页面的 slug 支持以及若干安全加固修复。

相对 partial 引用。 以 ./ 或 ../ 开头的 partial 名称现在会相对于调用 partial 所在的目录进行解析。这使得编写自包含、可移动的 partial 目录树变得容易得多,例如从 layouts/_partials/card/list.html 内部使用 {{ partial "./item.html" . }}。相对路径只允许在 partial 内部使用,解析到 partial 目录之外的路径会报错。参见 #15373 和文档。

section、taxonomy 和 term 页面的 slug。 slug front matter 现在对分支页面也生效,不再仅限于普通页面,并且会级联到后代页面。这在多语言站点中尤其有用,例如 content/help/_index.es.md 中写 slug: ayuda 会生成 /es/ayuda/、/es/ayuda/avanzado/ 等。参见 #14352。

其他值得注意的改进包括新增 build.cleanDestinationDir 配置及 keepFiles/keepDirs Glob 模式(#14937,文档)、hugo 现在可以在没有配置文件的情况下构建(#15393)、eq、where、in 以及集合函数中的精确数值比较(#15322、#15358),以及自动摘要不再结束于未闭合的列表或引用块内部(#14044)。

安全

本次发布包含多项加固修复。目前均未发现被利用的情况,但如果你使用不受信任的主题或模块构建站点,应当升级。

  • 未在 Hugo 文件系统中找到的 Sass 导入会由 Sass 编译器自行解析,它会跟随符号链接且对项目根目录一无所知。主题可以导入项目外的文件并将其内容带入发布的 CSS 中。这些导入现在由 Hugo 解析,并与 Node.js 工具和 js.Build 一样对照相同的 security.allowRead 根目录进行检查。41040cc7(感谢 @Hama1cco)
  • 同样,未在 /assets 中找到的导入此前由 ESBuild 自行解析和读取。现在 ESBuild 加载之前,解析出的路径会先对照允许的读取路径进行检查。2aa51f34(感谢 @Hama1cco)
  • 主题中位于嵌套挂载点父级的符号链接目录可能暴露模块之外的文件。2fe9bab7
  • 显式的标题 ID(例如 ## Foo {id="..."})会被未转义地写入目录的 href,从而允许属性逃逸。671fbf2c

注意

  • 默认 baseURL 现在是 https://example.org/(此前为空)。Hugo 一直都需要有效的 URL 才能正常工作,所以这主要影响新建和测试站点,但如果你依赖空默认值来生成相对 URL,请显式设置 baseURL。bc686541 @bep #14625 #15384
  • 根级 cleanDestinationDir 配置项已弃用,改用 build.cleanDestinationDir.enable。--cleanDestinationDir 标志映射到新的配置项。注意,发布目录中的 .git 文件现在默认会被保留。90861931 @bep #14937
  • eq 现在与 lt、le 等以相同方式比较数值,因此例如 eq 1 1.0 现在为 true。此外,in、intersect、union、uniq、symdiff、complement 以及 where 的 in/not in 现在精确比较数字而不再通过 float64,且不再要求 Go 类型一致。4d628bbd 366377b6 @bep #15322 #15358
  • 用户自定义的表格 render hook 现在优先于内置的 render hook。140d9362 @jmooring #15389
  • 必要时自动摘要会扩展超出 summaryLength,以避免结束于未闭合的容器元素内部。这可能会改变某些页面的摘要。d692a243 @bep #14044

Bug 修复

  • hugolib:修复失败的集成测试 fdbba5a6 @jmooring
  • 修复在 Fedora 44 Beta 上使用 Go 1.26 的构建问题 2782bfd3 @flyn-org
  • 修复带旋转的 smartcrop(#15371)5edd05bb @bep #11266 #15369
  • ci:修复损坏的 magefile 1d87ee5b @bep
  • tpl/collections:修复不同数值元素类型切片的 union ffbcdba9 @hktitof #15323
  • 修复同一批次中同一目录下多个文件变更时页面内容过期的问题 a374b865 @bep #15330

改进

  • 更新 .gitignore f6606f1f @bep
  • tocss:将 Sass 导入回退限制在允许的读取路径内 41040cc7 @bep
  • js:将 ESBuild 的回退解析器限制在允许的读取路径内 2aa51f34 @bep
  • commands:允许在没有配置文件的情况下构建 c7f99993 @bep #15393
  • collections:追加空切片时保留切片类型 dd16df14 @jakezwang #11131
  • tpl/tplimpl:用户自定义的表格 render hook 优先于内置 140d9362 @jmooring #15389
  • 避免在 SitesMatrix.MatchSiteVector 中分配内存 83ab7999 @bep
  • 为 section、taxonomy 和 term 页面添加 slug 支持 5d43ab70 @bep #14352
  • tpl:常见签名避免使用 reflect.Value.Call 806a62e8 @bep #15385
  • ci:运行测试时禁用 vet 8bac4de7 @bep
  • tpl/partials:支持从 partial 内部使用相对 partial 路径(#15376)bd1588bd @bep #15373
  • config:新增 build.cleanDestinationDir 配置 90861931 @bep #14937
  • commands:使 testscripts/commands/hugo__clean_destination_dir.txt 可移植 a74b7539 @bep #8433
  • commands:处理 cleanDestinationDir 中缺失的 staticDir 07b9fba1 @jmooring #8433
  • hugofs:缓存符号链接检查 09fa49be @bep
  • hugofs:丢弃嵌套挂载点虚拟祖先目录中的符号链接 2fe9bab7 @bep
  • markup/tableofcontents:在 ToC HTML 中转义标题 ID 671fbf2c @bep
  • hugofs:允许主项目中的符号链接挂载根目录 25f2856a @bep #15367
  • 扩展并整合 BOM 去除逻辑 cb6a7072 @bep #15355 #15361
  • tpl/collections:在集合运算和 where 中精确比较数字 366377b6 @bep #15358 #15359
  • ci:在 Windows 上跳过 vet 10bb97ba @bep
  • 回滚 “parser/metadecoders:在反序列化前去除数据中的 BOM” 51cd9e6c @bep
  • parser/metadecoders:在反序列化前去除数据中的 BOM ec578f0c @jmooring #15355
  • tpl:使用新版格式化工具重新格式化模板 5698de94 @bep
  • resources/page:在自动摘要中平衡容器标签 d692a243 @bep #14044 #14927
  • config/security:添加集成测试 3be817ed @bep
  • tpl/compare:整合数值比较 4d628bbd @bep #15322 #15347
  • tpl/strings:新增 strings.FirstLower 函数 aaacd12c @jmooring #15332
  • 更新 AGENTS.md 中的简洁性指南 881c0ec7 @bep

依赖更新

  • build(deps):将 github.com/olekukonko/tablewriter 从 1.1.4 升级到 1.1.5 1567bdef @dependabot[bot]
  • build(deps):将 github.com/dustin/go-humanize 从 1.0.1 升级到 1.1.0 9e4059cf @dependabot[bot]
  • build(deps):将 golang.org/x/tools 从 0.49.0 升级到 0.50.0 8e3bbe67 @dependabot[bot]
  • build(deps):将 golang.org/x/image 从 0.45.0 升级到 0.46.0 753c5fc1 @dependabot[bot]
  • build(deps):将 golang.org/x/text 从 0.41.0 升级到 0.42.0 facde8aa @dependabot[bot]
  • build(deps):将 go.opentelemetry.io/otel/sdk 从 1.44.0 升级到 1.45.0 c7e1a8e6 @dependabot[bot]
  • deps:将 github.com/bep/imagemeta 从 1.0.0 升级到 1.0.1(#15338)ec57bb7d @dependabot[bot] #15324

文档

  • readme:提升最低 Go 版本要求 7a46cd2b @mikoxyz

构建配置

  • 将发布镜像更新至 Go 1.27.1(#15342)34d8cdb1 @bep

更新内容 (原始)

This release brings relative partial references, slug support for branch pages, and a handful of security hardening fixes.

Relative partial references. A partial name starting with ./ or ../ is now resolved relative to the directory of the calling partial. This makes it much easier to write self-contained, movable partial trees, e.g. {{ partial "./item.html" . }} from within layouts/_partials/card/list.html. Relative paths are only allowed from within partials, and paths resolving outside the partials directory is an error. See #15373 and the documentation.

Slugs for section, taxonomy and term pages. The slug front matter now works for branch pages, not just regular pages, and it cascades to descendants. This is particularly useful in multilingual sites, where e.g. content/help/_index.es.md with slug: ayuda gives /es/ayuda/, /es/ayuda/avanzado/ etc. See #14352.

Other notable improvements include the new build.cleanDestinationDir config with keepFiles/keepDirs Glob patterns (#14937, docs), hugo now builds without a config file (#15393), exact numeric comparisons in eq, where, in and the set functions (#15322, #15358), and automatic summaries that no longer end inside an open list or blockquote (#14044).

Security

This release contains several hardening fixes. None of them are known to be exploited, but if you build sites with untrusted themes or modules, you should upgrade.

  • Sass imports not found in Hugo’s file systems were resolved by the Sass compiler itself, which follows symlinks and knows nothing about the project root. A theme could import a file outside the project and get its content into the published CSS. These imports are now resolved by Hugo and checked against the same security.allowRead roots as the Node.js tools and js.Build. 41040cc7 (thanks to @Hama1cco)
  • Likewise, imports not found in /assets were resolved and read by ESBuild itself. The resolved path is now checked against the allowed read paths before ESBuild loads it. 2aa51f34 (thanks to @Hama1cco)
  • A symlinked directory in a theme at the parent of a nested mount could expose files outside the module. 2fe9bab7
  • Explicit heading IDs (e.g. ## Foo {id="..."}) were written unescaped into the table of contents href, allowing attribute breakout. 671fbf2c

Note

  • The default baseURL is now https://example.org/ (it was empty). Hugo has always required a valid URL to work properly, so this mostly affects new and test sites, but if you relied on the empty default for relative URLs, set baseURL explicitly. bc686541 @bep #14625 #15384
  • The root cleanDestinationDir config key is deprecated in favour of build.cleanDestinationDir.enable. The --cleanDestinationDir flag maps to the new key. Note that .git files in the publish dir are now kept by default. 90861931 @bep #14937
  • eq now compares numeric values the same way as lt, le etc., so e.g. eq 1 1.0 is now true. Also, in, intersect, union, uniq, symdiff, complement and where’s in/not in now compare numbers exactly rather than via float64, and no longer require the Go types to match. 4d628bbd 366377b6 @bep #15322 #15358
  • A user table render hook is now preferred over the embedded one. 140d9362 @jmooring #15389
  • Automatic summaries are expanded past summaryLength when needed so they don’t end inside an open container element. This may change the summary for some pages. d692a243 @bep #14044

Bug fixes

  • hugolib: Fix failing integration test fdbba5a6 @jmooring
  • Fix build with Go 1.26 on Fedora 44 Beta 2782bfd3 @flyn-org
  • Fix smartcrop with rotation (#15371) 5edd05bb @bep #11266 #15369
  • ci: Fix broken magefile 1d87ee5b @bep
  • tpl/collections: Fix union of slices with different numeric element types ffbcdba9 @hktitof #15323
  • Fix stale page content when several files in the same dir change in one batch a374b865 @bep #15330

Improvements

  • Update .gitignore f6606f1f @bep
  • tocss: Confine Sass import fallbacks to the allowed read paths 41040cc7 @bep
  • js: Confine ESBuild’s fallback resolver to the allowed read paths 2aa51f34 @bep
  • commands: Allow building without a config file c7f99993 @bep #15393
  • collections: Preserve slice type when appending an empty slice dd16df14 @jakezwang #11131
  • tpl/tplimpl: Prefer user table render hook over embedded 140d9362 @jmooring #15389
  • Avoid allocating in SitesMatrix.MatchSiteVector 83ab7999 @bep
  • Add slug support for section, taxonomy and term pages 5d43ab70 @bep #14352
  • tpl: Avoid reflect.Value.Call for common signatures 806a62e8 @bep #15385
  • ci: Disable vet when running tests 8bac4de7 @bep
  • tpl/partials: Support relative partial paths from within partials (#15376) bd1588bd @bep #15373
  • config: Add build.cleanDestinationDir config 90861931 @bep #14937
  • commands: Make testscripts/commands/hugo__clean_destination_dir.txt portable a74b7539 @bep #8433
  • commands: Handle missing staticDir in cleanDestinationDir 07b9fba1 @jmooring #8433
  • hugofs: Cache symlink checks 09fa49be @bep
  • hugofs: Drop symlinks in virtual ancestor dirs of nested mounts 2fe9bab7 @bep
  • markup/tableofcontents: Escape heading IDs in ToC HTML 671fbf2c @bep
  • hugofs: Allow symlinked mount roots in the main project 25f2856a @bep #15367
  • Expand and consolidate BOM trimming cb6a7072 @bep #15355 #15361
  • tpl/collections: Compare numbers exactly in set operations and where 366377b6 @bep #15358 #15359
  • ci: Skip vet on Windows 10bb97ba @bep
  • Revert “parser/metadecoders: Strip BOM from data prior to unmarshalling” 51cd9e6c @bep
  • parser/metadecoders: Strip BOM from data prior to unmarshalling ec578f0c @jmooring #15355
  • tpl: Reformat templates with new formatter version 5698de94 @bep
  • resources/page: Balance container tags in automatic summaries d692a243 @bep #14044 #14927
  • config/security: Add an integration test 3be817ed @bep
  • tpl/compare: Consolidate numeric comparisions 4d628bbd @bep #15322 #15347
  • tpl/strings: Add a strings.FirstLower function aaacd12c @jmooring #15332
  • Update brevity guideline in AGENTS.md 881c0ec7 @bep

Dependency Updates

  • build(deps): bump github.com/olekukonko/tablewriter from 1.1.4 to 1.1.5 1567bdef @dependabot[bot]
  • build(deps): bump github.com/dustin/go-humanize from 1.0.1 to 1.1.0 9e4059cf @dependabot[bot]
  • build(deps): bump golang.org/x/tools from 0.49.0 to 0.50.0 8e3bbe67 @dependabot[bot]
  • build(deps): bump golang.org/x/image from 0.45.0 to 0.46.0 753c5fc1 @dependabot[bot]
  • build(deps): bump golang.org/x/text from 0.41.0 to 0.42.0 facde8aa @dependabot[bot]
  • build(deps): bump go.opentelemetry.io/otel/sdk from 1.44.0 to 1.45.0 c7e1a8e6 @dependabot[bot]
  • deps: Bump github.com/bep/imagemeta from 1.0.0 to 1.0.1 (#15338) ec57bb7d @dependabot[bot] #15324

Documentation

  • readme: Bump minimum Go version 7a46cd2b @mikoxyz

Build Setup

  • Update release image to Go 1.27.1 (#15342) 34d8cdb1 @bep

下载链接