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

Custom collections with pagination #273

Open
cossssmin opened this issue Sep 24, 2018 · 4 comments
Open

Custom collections with pagination #273

cossssmin opened this issue Sep 24, 2018 · 4 comments

Comments

@cossssmin
Copy link

cossssmin commented Sep 24, 2018

This came about after not being able to paginate a dynamically-generated collection (original discussion here). I've been recently working on a Jigsaw blog template, and I needed support for paginated index pages for collections created on-the-fly, through an event listener.

In my case, I needed tags/categories. Using @nikazooz's example, I got the tags working but after several attempts it was clear (and @damiani confirmed) that it's currently not possible to paginate such collections.

Although this started from paginating dynamically-generated collections, I think we can take it a step further and think about providing support for 'custom post types', kind of like WordPress does. This would be very compelling for people looking to switch to a static blog, as it would allow them to keep their site's structure.

Here are a few ideas regarding functionality workflow. Let's discuss:

1. Generic

A collection meant for custom types such as tags, should not be opinionated.

Ideally, you want the freedom to display your content/posts grouped in various ways: tags, categories, authors (imagine multi-author posts, and paginated index pages for an author's posts), posts by month, etc.

In this regard, I like @nikazooz's approach. He registers each collection in a class handled in an event.

The best thing about it, from a user perspective, is that you don't need to create files for the collection: no need for a _tags folder where each file would define a tag. Instead, you use YAML front matter keys with array values:

extends: _layouts.post
section: content
tags: ['events', 'development']

The helper method on your class then fetches all posts with that front matter key, and builds up the collection (example).

2. Paginated

Of course, any type of collection should allow for pagination.

In this regard, I think the simplest way would be to allow for a pagination key on any collection (thus making the current pagination feature obsolete?):

'collections' => [
      'tags' => [
          'pagination' => true,
          'perPage' => 5, // optional, default to 10 just like it does now
          'sort' => '-name',
          'extends' => '_layouts.tags.index',
          'section' => 'content',
          'path' => 'tag/{-name}',
      ],
],

With those settings, Jigsaw would paginate our tags collection, just like it paginates posts today, so you would get a /tag folder with a structure like this:

/tag/events
/tag/events/2
/tag/development
/tag/development/2
/tag/development/3

This should work even if the collection is generated in an event listener.

Note: there's also #272 which, if implemented, this would need to play nice with.


Looking forward to reading everyone's thoughts on this. Let's discuss :)

@damiani damiani changed the title [Proposal] Custom collections with pagination Custom collections with pagination Oct 2, 2018
@virulaine
Copy link

Any update please? This is urgently needed when generating pages from external JSON provided by API

@migsyboy
Copy link

What's the status of this?

@barthusz
Copy link

barthusz commented Sep 4, 2021

Hi there!

I would also like to know the status. Hope pagination for categories will be possible soon!
Looking forward to an answer :)

@milon
Copy link

milon commented Jul 10, 2022

Hey there, what is the status of this? Is it possible yet?

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

No branches or pull requests

6 participants