如何修复 Hugo:can't evaluate field IsServer in type interface {}

问题:

构建 Hugo 站点时,你看到如下错误消息:

hugo_isserver_error.txt
03:27:57.943	ERROR render of "page" failed: "/opt/buildhome/repo/themes/tailbliss/layouts/_default/baseof.html:5:7": execute of template failed: template: _default/single.html:5:7: executing "_default/single.html" at <partial "head.html" .>: error calling partial: "/opt/buildhome/repo/themes/tailbliss/layouts/partials/head.html:25:6": execute of template failed: template: partials/head.html:25:6: executing "partials/head.html" at <hugo>: can't evaluate field IsServer in type interface {}

解决方案

此问题由 Hugo 找不到 .IsServer 引起:

error_excerpt.txt
can't evaluate field IsServer in type interface {}

例如在以下模板代码中:

hugo_template_example.html
{{ if hugo.IsServer }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" />
{{ end }}

然而,.IsServer 仅在版本 0.120.0 中添加到 Hugo,所以如果你使用较旧版本,你会看到此错误。

修复很简单。你可以:

注意: 对于 Cloudflare Pages,你可以将部署环境变量 HUGO_VERSION 设置为 0.120.0 或更新版本以修复此问题。我用 0.134.2 测试过,工作正常。


Check out similar posts by category: Hugo