由于 Format() 在类型 toml.LocalDate 上不可用,站点构建失败
Site build fails due to Format() not being available on Type toml.LocalDate
当我使用管道在 Hugo 上构建站点时,构建经常失败并出现以下错误:
Error: Error building site:
failed to render pages: render of "home" failed: execute of template failed: template: index.html:22:11: executing "main" at <partial "session-dates.html" .>:
error calling partial: "/github/workspace/layouts/partials/session-dates.html:4:20":
execute of template failed: template: partials/session-dates.html:4:20:
executing "partials/session-dates.html" at <.Site.Params.current_startDate.Format>: can't evaluate field Format in type toml.LocalDate
错误发生在 current_startDate
和 current_endDate
值上,表示该类型没有可用的 Format 函数。配置为:
baseURL = "..."
languageCode = "en-us"
title = "..."
summaryLength = 20
relativeURLs = true
[params]
current_startDate = 2021-10-10
current_endDate = 2021-12-04
则模板代码为:
<div class="row">
<div class="col-lg-12 dates">
<span class="long-dates">
{{ .Site.Params.current_startDate.Format "January 2, 2006" }} —
{{ .Site.Params.current_endDate.Format "January 2, 2006" }}
</span>
<span class="short-dates">
{{ .Site.Params.current_startDate.Format "01/02/06" }} —
{{ .Site.Params.current_endDate.Format "01/02/06" }}
</span>
</div>
</div>
我已经尝试查看文档和其他示例,配置似乎是正确的,所以我认为我遗漏了一些明显的东西。
如果其他人 运行 关注此问题,出于某种原因,特别是在管道 https://github.com/chabad360/hugo-gh-pages 上,这是行不通的。在本地测试原始格式时,我可以在命令行进行构建和预览。
解决方法是提供完整的日期时间格式,因此对于我上面的示例是:
baseURL = "..."
languageCode = "en-us"
title = "..."
summaryLength = 20
relativeURLs = true
[params]
current_startDate = 2021-10-10T14:15:59-06:00
current_endDate = 2021-12-04T14:15:59-06:00
此配置在本地和管道中按预期构建。
当我使用管道在 Hugo 上构建站点时,构建经常失败并出现以下错误:
Error: Error building site:
failed to render pages: render of "home" failed: execute of template failed: template: index.html:22:11: executing "main" at <partial "session-dates.html" .>:
error calling partial: "/github/workspace/layouts/partials/session-dates.html:4:20":
execute of template failed: template: partials/session-dates.html:4:20:
executing "partials/session-dates.html" at <.Site.Params.current_startDate.Format>: can't evaluate field Format in type toml.LocalDate
错误发生在 current_startDate
和 current_endDate
值上,表示该类型没有可用的 Format 函数。配置为:
baseURL = "..."
languageCode = "en-us"
title = "..."
summaryLength = 20
relativeURLs = true
[params]
current_startDate = 2021-10-10
current_endDate = 2021-12-04
则模板代码为:
<div class="row">
<div class="col-lg-12 dates">
<span class="long-dates">
{{ .Site.Params.current_startDate.Format "January 2, 2006" }} —
{{ .Site.Params.current_endDate.Format "January 2, 2006" }}
</span>
<span class="short-dates">
{{ .Site.Params.current_startDate.Format "01/02/06" }} —
{{ .Site.Params.current_endDate.Format "01/02/06" }}
</span>
</div>
</div>
我已经尝试查看文档和其他示例,配置似乎是正确的,所以我认为我遗漏了一些明显的东西。
如果其他人 运行 关注此问题,出于某种原因,特别是在管道 https://github.com/chabad360/hugo-gh-pages 上,这是行不通的。在本地测试原始格式时,我可以在命令行进行构建和预览。
解决方法是提供完整的日期时间格式,因此对于我上面的示例是:
baseURL = "..."
languageCode = "en-us"
title = "..."
summaryLength = 20
relativeURLs = true
[params]
current_startDate = 2021-10-10T14:15:59-06:00
current_endDate = 2021-12-04T14:15:59-06:00
此配置在本地和管道中按预期构建。