我有一个Hugo列表模板,如下所示:
{{ range (.Paginate (.Data.Pages.GroupByDate "2006")).PageGroups }}
<h3>{{ .Key }}</h3>
<ul>
{{ range .Pages.ByWeight }}
<li>
<a href="{{ .Permalink }}">{{ if .Draft }}{{ T "draft" }}: {{end}}{{ .Title | markdownify }}</a>
<time class="date-meta">{{ .Date.Format "Jan 2" }}</time>
</li>
{{ end }}
</ul>
{{ end }}
当我像这样运行hugo server -D
网站时,它运行得很好。
当我建立网站我得到:
执行模板失败:template:_default/list.html:15:14:在<执行"main";。Paginate>:调用Paginate时出错:无法转换类型页。页面分组到页面启用调试和详细功能没有帮助。我有:
content
content/web
content/web/one.md
content/web/two.md
content/web/_index.md
content/web/three.md
content/about
content/about/index.md
什么东西?
我在编写自定义主题时遇到此错误,但在运行hugo -D
或hugo server -D
时除外。作为一种变通方法,请尝试将其封装在if
条件中以检查.Data.Pages
。
{{ if .Data.Pages }}
{{ range (.Paginate (.Data.Pages.GroupByDate "2006")).PageGroups }}
...
{{ end }}
{{ end }}