-
Notifications
You must be signed in to change notification settings - Fork 188
Description
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 :)