Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Posts paginator error, fails on hugo server --buildDrafts #165

Closed
FN-FAL113 opened this issue Feb 24, 2024 · 2 comments · Fixed by #170
Closed

Posts paginator error, fails on hugo server --buildDrafts #165

FN-FAL113 opened this issue Feb 24, 2024 · 2 comments · Fixed by #170

Comments

@FN-FAL113
Copy link

FN-FAL113 commented Feb 24, 2024

Describe the bug
Seems like there is an error with the paginator, I'm new to using this theme and first time I encountered this issue.

Steps to reproduce
Steps to reproduce the behavior:

  1. create new posts with hugo new content command
  2. open development server with build draft posts with hugo server --buildDrafts
  3. throws an error
Error: error building site: render: failed to render pages: render of "page" failed: "C:\Users\orbet\Documents\GitHub\FNDev-Blogs\themes\hugo-blog-awesome\layouts\_default\baseof.html:3:8": execute of template failed: template: _default/single.html:3:8: executing "_default/single.html" at <partial "head.html" .>: error calling partial: "C:\Users\orbet\Documents\GitHub\FNDev-Blogs\themes\hugo-blog-awesome\layouts\partials\head.html:2:8": execute of template failed: template: partials/head.html:2:8: executing "partials/head.html" at <partial "meta/main.html" .>: error calling partial: "C:\Users\orbet\Documents\GitHub\FNDev-Blogs\themes\hugo-blog-awesome\layouts\partials\meta\main.html:2:3": execute of template failed: template: partials/meta/main.html:2:3: executing "partials/meta/main.html" at <partial "meta/post.html" .>: error calling partial: "C:\Users\orbet\Documents\GitHub\FNDev-Blogs\themes\hugo-blog-awesome\layouts\partials\meta\post.html:5:21": execute of template failed: template: partials/meta/post.html:5:21: executing "partials/meta/post.html" at <.Paginate>: error calling Paginate: pagination not supported for this page: kind: "page", path: "/posts/event-capture",

Expected behavior
Should properly serve with build drafts argument on dev server

Screenshots
The lines that causes the error inside themes\hugo-blog-awesome\layouts\partials\meta\post.html:
image

Device information

  • OS: Windows
  • Browser: Chrome/Edge
  • Version latest
@FN-FAL113 FN-FAL113 changed the title Posts aginator error, fails on hugo server --buildDrafts Posts paginator error, fails on hugo server --buildDrafts Feb 24, 2024
gian-hancock pushed a commit to gian-hancock/gian-hancock.github.io that referenced this issue Feb 27, 2024
@deining
Copy link
Contributor

deining commented Feb 29, 2024

I encountered this error too when previewing the example site. Quickly I realized that this error happens with hugo version v0.123.7 only. With hugo 0.122.0, preview of the example site works fine.

@MichielVanDerWinden
Copy link
Contributor

I had some time left this morning so I looked into the issue and found that since v0.123.0 Hugo no longer allows pages of kind "Page" to create a .Paginate or .Paginator.
For now I've fixed it in my post.html by adding the following:

    {{ if ne .Page.Kind "page" }}
    {{ $paginator := .Paginate (where .Pages "Section" "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 }}
    {{end }}

The only addition is the inclusion of an if-statement to check what kind of page we're on and prevent creation of the paginator on any pages of kind "page". This makes it possible for your posts overview (e.g. /posts) to create a paginator and use that in the post.html instantiaton, resulting in the <head> containing the specific pagination <link> references:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants