更新Hugo后网站错误的解决方案

2025-03-19
#Blog #Unix

在 macOS 上,利用 brew upgrade hugo 更新 Hugo 至 hugo 0.145.0 后,出现以下各种错误。

1. Hugo渲染模板文件错误

Error: error building site: render: failed to render pages: render of “/” failed: execute of template failed: html/template:index.html:63:12: no such template “_internal/google_analytics_async.html”

解决方案:在路径 /themes/主题名/layouts/_default/baseof.html,将

{{ template "_internal/google_analytics_async.html" . -}}

换为

{{ template "_internal/google_analytics.html" . -}}

2. Hugo翻页错误

ERROR deprecated: site config key paginate was deprecated in Hugo v0.128.0 and subsequently removed. Use pagination.pagerSize instead.

解决方案:在 hugo v0.128.0 之后,paginate 配置项不能再用了。在 config.toml 里,将

paginate = 100

改为

pagerSize = 100

3. Hugo搜索文件日期错误

ERROR the “date” front matter field is not a parsable date: see /blog/content/search.md

解决方案:在Hugo网站设置Pagefind本地搜索(3)设置了搜索文件,在search.md中删除date一行 date: 2024-01-13T16:54:22+01:00

4. 谷歌ID提醒

WARN Google Analytics 4 (GA4) replaced Google Universal Analytics (UA) effective 1 July 2023. See https://support.google.com/analytics/answer/11583528. Create a GA4 property and data stream, then replace the Google Analytics ID in your site configuration with the new value.

解决方案:旧的 Google Universal Analytics 已经停用,需要用 GA4 的新 ID (“管理” → “数据流” → “衡量 ID”)。在 config.toml 里,将

googleAnalytics = "UA-XXXXX-Y"

改为

googleAnalytics = "G-XXXXXXX"