hugo-theme-diary icon indicating copy to clipboard operation
hugo-theme-diary copied to clipboard

error calling Paginator: pagination not supported for this page

Open LinkSake opened this issue 1 year ago • 5 comments

Describe the bug In a newly created Hugo project, with just the hugo.toml modified, after creating a post an error will rise:

Failed to render "/posts/post-1/": render: failed to render pages: render of "page" failed: [1;36m"/Users/angel/Documents/spicer/themes/diary/layouts/_default/baseof.html:15:16"[0m: execute of template failed at <partial "extrabar.html" .>: error calling partial: [1;36m"/Users/angel/Documents/spicer/themes/diary/layouts/partials/extrabar.html:28:19"[0m: execute of template failed at <.Paginator>: error calling Paginator: pagination not supported for this page: kind: "page", path: "/posts/post-1", file: "/Users/angel/Documents/spicer/content/posts/post-1.md" 

To Reproduce

  1. I have only one post, a clone of exampleSite/content/posts/post-1.md

  2. hugo.toml:

baseURL = 'https://example.org/'
DefaultContentLanguage= 'es'
languageCode = 'es-mx'
title = 'Foo'
theme = 'diary'
copyright = 'Foo'

[params]
   subtitle = 'Foo'
   enableReadingTime=true   
   disableToC=true

[taxonomies]
   category = "categories"
   tag = "tags"

[[menu.main]]
   url = "/posts"
   name = "Archivo"
   weight = 1
[[menu.main]]
   url = "/categories"
   name = "Categorias"
   weight = 2
[[menu.main]]
   url = "/tags"
   name = "Tags"
   weight = 3

Expected behavior

Hugo project should not have an issue running.

Screenshots

Screenshot 2024-02-21 at 14 50 52

Environment

  • Hugo: hugo v0.123.1-3f8434a62fc91a50f4e5bd43a4435d2d301844ff+extended darwin/arm64 BuildDate=2024-02-21T08:17:45Z VendorInfo=brew
  • Browser: Brave v 1.62.165

Additional context

Removing {{- partial "extrabar.html" . -}} and {{- partial "mobile-footer.html" . -}} from themes/diary/layouts/_default/baseof.html solves the issue, but this will take funcionality out.

LinkSake avatar Feb 21 '24 20:02 LinkSake

This error is with the latest version of Hugo, released a few a few days ago. Most likely has to do with this issue and corresponding changes.

In Hugo, the .Paginator is primarily designed for use in list templates where pagination is needed to navigate through lists of content, such as posts in a blog. It is not typically used within _default single page templates (e.g., single.html) because these templates are intended for individual content pages that don't require pagination.

The pagination logic needs to be moved to list templates, for example index.html. I tested this and it works, but my UI skills are horrible so no PR yet.

IrisClasson avatar Feb 22 '24 06:02 IrisClasson

Screenshot 2024-02-22 at 10 21 03

I moved the pagination logic to index.html and that works well. As mentioned, my UI skills are not very good, but this is how it looks like now. I added navigation to the top as well, and the same navigation for non-mobile view (in other words, the pagination is always at the top and bottom).

Parts of index.html. Please ignore inline styling, will fix.

{{ define "main" }}
<div ref="streamContainer" class="stream-container">
    <div style="display: flex; align-items: center; justify-content: center;  padding: 2% 0;"> 
        {{ if .Paginator.HasPrev }}
        <a class="pagination-action" href="{{.Paginator.Prev.URL}}" style="opacity:1">
            {{ else }}
            <a class="pagination-action" style="opacity:0">
                {{ end }}
                <svg width="1.5rem" height="1.5rem" viewBox="0 0 50 50" style="margin-right:0.5rem">
                    <polygon points="10,0 40,25 10,50" fill="#188476" transform="rotate(180 25 25)"/>
                  </svg>                  
            </a>
            <div class="pagination-indicator" style="color: #188476; font-weight: bolder;">
                <span>{{.Paginator.PageNumber}}/{{.Paginator.TotalPages}}</span>
            </div>
    
            {{ if .Paginator.HasNext }}
            <a class="pagination-action" href="{{.Paginator.Next.URL}}" style="opacity:1;">
                {{ else }}
                <a class="pagination-action" style="opacity:0;">
                    {{ end }}
                    <svg width="1.5rem" height="1.5rem" viewBox="0 0 50 50" style="margin-left:0.5rem">
                        <polygon points="10,0 40,25 10,50" fill="#188476"/>
                      </svg>     
                </a>
    </div>
        <div class="post-list-container post-list-container-no-background">
        <!-- the rest of the index.html page. Navigation also added to bottom -->

IrisClasson avatar Feb 22 '24 10:02 IrisClasson

Hi @IrisClasson, I clicked the issue you've mentioned and just add (.Page.IsNode) to the statement in line 28 of extrabar.html and line 1 of mobile-paginator.html like what was said there and it seems to build successfully as before.

- {{ if and (.Paginator) (not (.Data.Terms)) }}
+ {{ if and (.Page.IsNode) (.Paginator) (not (.Data.Terms)) }}

It just seems to work, but I'm not familiar with Hugo so I don't know if this is a decent fix. 😊

kLiHz avatar Feb 25 '24 06:02 kLiHz

@kLiHz This simple fix just works fine.

cjc7373 avatar Feb 25 '24 09:02 cjc7373

Hi @IrisClasson, I clicked the issue you've mentioned and just add (.Page.IsNode) to the statement in line 28 of extrabar.html and line 1 of mobile-paginator.html like what was said there and it seems to build successfully as before.

- {{ if and (.Paginator) (not (.Data.Terms)) }}
+ {{ if and (.Page.IsNode) (.Paginator) (not (.Data.Terms)) }}

It just seems to work, but I'm not familiar with Hugo so I don't know if this is a decent fix. 😊

This should work fine if some changes made:

- {{ if and (.Paginator) (not (.Data.Terms)) }}
+ {{ if and (.IsNode) (.Paginator) (not (.Data.Terms)) }}

I've just updated the hugo to 0.124.1 and got the same errors. These changes can fix for this theme.

@kLiHz don't be heisitated to send a PR~

Great thanks all of you.

shinyzhu avatar Mar 23 '24 09:03 shinyzhu