lukeorth / poison

Professional Hugo theme for dev bloggers. Based on Mdo's classic Hyde theme.
https://poison.lukeorth.com
GNU General Public License v3.0
172 stars 94 forks source link

Build fails on hugo v0.123: pagination not supported for this page: kind: "page" #169

Closed alexishuf closed 4 months ago

alexishuf commented 4 months ago

Poison site does not build with hugo 0.123.0 and 0.123.1, but builds with v0.122.0

Steps to reproduce:

hugo new site test
cd test
git clone --depth=1 https://github.com/lukeorth/poison themes/poison
# add minimal config to hugo.toml:
cat >>hugo.toml <<EOF
theme = 'poison'

[params]
brand = 'my_brand'
menu = [
  {Name = "About", URL = "/about/", HasChildren = false},
  {Name = "Posts", URL = "/posts/", HasChildren = true, Limit = 5},
]
EOF
hugo new content posts/hello/index.md
hugo -D

Outputs:

Start building sites …
hugo v0.123.0+extended linux/amd64 BuildDate=unknown

Total in 49 ms
Error: error building site: render: failed to render pages: render of "page" failed: "/home/alexis/sources/test/themes/poison/layouts/_default/baseof.html:1:3": execute of template failed: template: _default/single.html:1:3: executing "_default/single.html" at <partial "head/head.html" .>: error calling partial: "/home/alexis/sources/test/themes/poison/layouts/partials/head/head.html:16:7": execute of template failed: template: partials/head/head.html:16:7: executing "partials/head/head.html" at <partial "head/meta.html" .>: error calling partial: "/home/alexis/sources/test/themes/poison/layouts/partials/head/meta.html:96:17": execute of template failed: template: partials/head/meta.html:96:17: executing "partials/head/meta.html" at <.Paginate>: error calling Paginate: pagination not supported for this page: kind: "page", path: "/posts/hello", file: "/home/alexis/sources/test/content/posts/hello/index.md"

the issue happens without -D, provided draft = true is changed at hello/index.md

The relevant code in layouts/partials/head/meta.html:

<!-- Pagination meta tags for list pages only -->
{{ $paginator := .Paginate (where .Pages "Type" "posts") }}
{{ if $paginator }}
  <link rel="first" href="{{ $paginator.First.URL }}" />
  <link rel="last" href="{{ $paginator.Last.URL }}" />
  {{ if $paginator.HasPrev }}
    <link rel="prev" href="{{ $paginator.Prev.URL }}" />
  {{end }}
  {{ if $paginator.HasNext }}
    <link rel="next" href="{{ $paginator.Next.URL }}" />
  {{end }}
{{end }}

Deleting this code gets the build to complete.

gohugoio/hugo#11954, merged into hugo 0.123.0 might be related. My understanding of hugo is limited and as there was no issue reported on the hugo repo yet, it could be a poison issue.

x-zvf commented 4 months ago

I am encountering the same issue.. :(

sudomateo commented 4 months ago

Also encountering this issue. Found a nice blog post about it at https://www.irisclasson.com/2024/02/21/hugo-error-calling-paginator/.

For now I made the following change to override the layout.

diff --git a/layouts/partials/head/meta.html b/layouts/partials/head/meta.html
index 691f114..cb9c888 100644
--- a/layouts/partials/head/meta.html
+++ b/layouts/partials/head/meta.html
@@ -92,18 +92,6 @@
 <!-- Article Specific Tags -->
 <!-- To make sure this renders only in the article page, we check the section -->
 {{ if eq .Section "posts" }}
-<!-- Pagination meta tags for list pages only -->
-{{ $paginator := .Paginate (where .Pages "Type" "posts") }}
-{{ if $paginator }}
-  <link rel="first" href="{{ $paginator.First.URL }}" />
-  <link rel="last" href="{{ $paginator.Last.URL }}" />
-  {{ if $paginator.HasPrev }}
-    <link rel="prev" href="{{ $paginator.Prev.URL }}" />
-  {{end }}
-  {{ if $paginator.HasNext }}
-    <link rel="next" href="{{ $paginator.Next.URL }}" />
-  {{end }}
-{{end }}

 <meta property="og:type" content="article" />
 <meta property="article:publisher" content="{{ .Site.Params.facebook_url }}" />
ctmbl commented 4 months ago

I have no clue neither if this bug is really from hugo or poison, given https://github.com/gohugoio/hugo/issues/11949 and https://github.com/gohugoio/hugo/issues/12080 I'd say poison though, hugo maintainers seem to stick with their changes.

Anyway I cloned hugo's repo and using git bisect managed to identify the commit introducing (or triggering) this behavior: https://github.com/gohugoio/hugo/commit/6c3b6ba3e6ccc220cbca9cc83fab78db0a78604e I'm not used to hugo's code so I don't know if I'll do something of it but here it is if someone needs it

also https://github.com/AmazingRise/hugo-theme-diary/issues/177#issuecomment-1962833666 seems to be a fix, don't really know if this applies well to poison though

FLopriore commented 4 months ago

also AmazingRise/hugo-theme-diary#177 (comment) seems to be a fix, don't really know if this applies well to poison though

I applied this fix and it compiles successfully.

Replace line 94 in layouts/partials/head/meta.html: {{ if eq .Section "posts" }} with: {{ if and (eq .Section "posts") (.Page.IsNode) }}

ctmbl commented 4 months ago

@FLopriore it seems to fix it, could you propose a PR to the repo?

FLopriore commented 4 months ago

@FLopriore it seems to fix it, could you propose a PR to the repo?

Yes, I do it right now

lukeorth commented 4 months ago

Thanks, everyone! Sorry for being MIA the past several weeks. PR is merged. :+1:

sudomateo commented 4 months ago

Thank you! Updated my website to the latest version and it's working well.