hugo-theme-diary
hugo-theme-diary copied to clipboard
error calling Paginator: pagination not supported for this page
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
-
I have only one post, a clone of
exampleSite/content/posts/post-1.md
-
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
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.
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.
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 -->
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 This simple fix just works fine.
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.