I’m trying to list “pinned” and “unpinned” pages in a Hugo section separately:
{{ range (where $page.Pages "Params.paige.pin" true).ByPublishDate.Reverse }}
{{ partial "paige/page.html" . }}
{{ end }}
{{ $ps1 := $page.Pages }}
{{ $pgs := $ps1.ByPublishDate.Reverse.GroupByPublishDate "January 2006" }}
{{ $p := $page.Paginate $pgs }}
{{ range $p.PageGroups }}
<p class="h5 paige-date-header text-center">{{ .Key }}</p>
{{ range .Pages }}
{{ partial "paige/page.html" . }}
{{ end }}
{{ end }}
This works with 5 pages (1 pinned) and paginate: 10
in config.yaml.
However, the second list has pinned posts in it. When I try to filter them out (see $ps2
line)
{{ range (where $page.Pages "Params.paige.pin" true).ByPublishDate.Reverse }}
{{ partial "paige/page.html" . }}
{{ end }}
{{ $ps2 := where $page.Pages "Params.paige.pin" "ne" true }}
{{ $pgs := $ps2.ByPublishDate.Reverse.GroupByPublishDate "January 2006" }}
{{ $p := $page.Paginate $pgs }}
{{ range $p.PageGroups }}
<p class="h5 paige-date-header text-center">{{ .Key }}</p>
{{ range .Pages }}
{{ partial "paige/page.html" . }}
{{ end }}
{{ end }}
this also works.
However, if I set paginate: 1
in config.yaml, I get an error:
❯ hugo server --themesDir ../.. --enableGitInfo
Start building sites …
hugo v0.111.1+extended darwin/amd64 BuildDate=unknown
Error: Error building site: failed to render pages: render of "term" failed: "/Users/Will/Developer/paige/layouts/_default/term.html:5:3": execute of template failed: template: _default/term.html:5:3: executing "main" at <partial "paige/pages.html" $page>: error calling partial: "/Users/Will/Developer/paige/layouts/partials/paige/pages.html:26:26": execute of template failed: template: partials/paige/pages.html:26:26: executing "partials/paige/pages.html" at <$page.Paginate>: error calling Paginate: cannot convert type page.PagesGroup to Pages
Built in 336 ms
OK, let’s set paginate: 10
again. But we still get the error:
❯ hugo server --themesDir ../.. --enableGitInfo
Start building sites …
hugo v0.111.1+extended darwin/amd64 BuildDate=unknown
Error: Error building site: failed to render pages: render of "term" failed: "/Users/Will/Developer/paige/layouts/_default/term.html:5:3": execute of template failed: template: _default/term.html:5:3: executing "main" at <partial "paige/pages.html" $page>: error calling partial: "/Users/Will/Developer/paige/layouts/partials/paige/pages.html:26:26": execute of template failed: template: partials/paige/pages.html:26:26: executing "partials/paige/pages.html" at <$page.Paginate>: error calling Paginate: cannot convert type page.PagesGroup to Pages
Built in 292 ms
How about if we delete resources and public?
~/Developer/paige/exampleSite master* ⇡
❯ rm -rf resources public
~/Developer/paige/exampleSite master* ⇡
❯ hugo server --themesDir ../.. --enableGitInfo
Start building sites …
hugo v0.111.1+extended darwin/amd64 BuildDate=unknown
Error: Error building site: failed to render pages: render of "term" failed: "/Users/Will/Developer/paige/layouts/_default/term.html:5:3": execute of template failed: template: _default/term.html:5:3: executing "main" at <partial "paige/pages.html" $page>: error calling partial: "/Users/Will/Developer/paige/layouts/partials/paige/pages.html:26:26": execute of template failed: template: partials/paige/pages.html:26:26: executing "partials/paige/pages.html" at <$page.Paginate>: error calling Paginate: cannot convert type page.PagesGroup to Pages
Built in 3299 ms
Still get the error.
What if we change back to $ps1
?
{{ range (where $page.Pages "Params.paige.pin" true).ByPublishDate.Reverse }}
{{ partial "paige/page.html" . }}
{{ end }}
{{ $ps1 := $page.Pages }}
{{ $pgs := $ps1.ByPublishDate.Reverse.GroupByPublishDate "January 2006" }}
{{ $p := $page.Paginate $pgs }}
{{ range $p.PageGroups }}
<p class="h5 paige-date-header text-center">{{ .Key }}</p>
{{ range .Pages }}
{{ partial "paige/page.html" . }}
{{ end }}
{{ end }}
Now there’s no error.
What’s going on? What does “error calling Paginate: cannot convert type page.PagesGroup to Pages” mean? Why is that a problem when I filter pages with where
, but not a problem if I don’t? And why does the pagination limit in config.yaml affect this?
Edit: Code at GitHub - willfaught/paige at pin (last commit).