.Paginate on custom grouping of terms does not work

I am trying to create a page for a taxonomy that groups pages by the first letter of the title. For this, I created layouts/projects/taxonomy.html, that calls layouts/partials/projects/GroupByTitleFirstLetter.html to perform the grouping, any everything works fine.

However, I cannot seem to paginate the results using .Paginate, because it expects Pages but receives a []map[string]interface{}. I found it weird, because I thought the pagination worked also with the grouping functions, and if I am not mistaken, they return a slice of strucs containing Key and Pages, right?

Anyway, when I then tried to simply paginate the pages of the taxonomy on the page, the result was always nil. I checked if .Paginate is used in the theme, but it only seems to be used in layout/index.html, and if I am not mistaken, it should not interfere with the generation of a taxonomy page, right?

Could you please help me find a way to paginate those results?

not in pagination, but just a hint here:

According to the docs, the GroupBy return a new object page.PagesGroup so imho it’s not a simple slice of maps you can create manually.

From the documentation, we have:

type PagesGroup []PageGroup

(in hugo/resources/page/pagegroup.go at b39b24962350090122b5f3927456dde710cffb57 · gohugoio/hugo · GitHub)
and

// PageGroup represents a group of pages, grouped by the key.
// The key is typically a year or similar.
type PageGroup struct {
	// The key, typically a year or similar.
	Key any

	// The Pages in this group.
	Pages
}

(in hugo/resources/page/pagegroup.go at b39b24962350090122b5f3927456dde710cffb57 · gohugoio/hugo · GitHub).

This is why I hoped that recreating a dict containing a Key and a Pages entry could work.

I revised my Go notions, and indeed there does not seem to be a way to do that right now.
However, maybe it’d be possible to extend the library to have GroupBy accept some logic through for example a block name that would return a key for each page?

I’m not that deep in go. but usually ghe internal structure is not directly exposed to hugo but provided by interfaces hiding the details.

nevertheless. providing some more details on the intended output, someone could provide something for you.

as of now it’s unclear (to me) what the result should be. your repo has just two projects and two distinct starting letters. nkt much to paginate here :wink:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.