英文:
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>
我已经尝试查看文档和其他示例,配置似乎是正确的,所以我认为可能有一些明显的遗漏。
英文:
When I am building a site on Hugo using a pipeline, the build constantly fails with the following error:
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
The error is happening on the current_startDate
, and current_endDate
values, where it's saying there is no Format function available for the type. The config is:
baseURL = "..."
languageCode = "en-us"
title = "..."
summaryLength = 20
relativeURLs = true
[params]
current_startDate = 2021-10-10
current_endDate = 2021-12-04
Then the template code is:
<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>
I have tried looking at the docs and other examples and the configuration seems to be correct, so I assume there is something obvious I am missing.
答案1
得分: 0
如果其他人遇到了这个问题,特别是在这个管道上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
这个配置在本地和管道中都能正常构建。
英文:
If anyone else is running into this issue, for some reason specifically on the pipeline https://github.com/chabad360/hugo-gh-pages this doesn't work. When testing locally the original format I had works for both building and previewing at the command line.
The fix is to give the full datetime format, so for my example above that is:
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
This configuration builds as expected locally, and in the pipeline.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论