eleventy
eleventy copied to clipboard
Specify minimum number of items on last page of pagination
I use pagination in reverse for my blog. page-1 has the oldest content, page-N has the newest. I also setup my permalink such that page-N is just /blog/
This setup prevents me from churning old pages just to rewrite the entire blog list. So, basically when I reprocess my site, only the last 1 or 2 pages actually get changed when new content is added.
Adding a field to the pagination plugin like, minimumRemainder where it could be used as follows... if my pagination size is 9 and minimum remainder is 6 then, if the last page would end up with less than 6 (e.g. 5 or less), that remainder would get pulled into the final page, yielding a total of minimum 9 and a maximum of 14.
I have a work around for this with some sneaky helpers that calculate the page position in the index and how many items are in that last page to get all the pagination working... and the 2nd to last page just doesn't get linked in the previous / next links I create... my final page uses a server fetch to get the previous page content and I merge it in manually. It works, it is hacky and this change in pagination would be a great addition.
I think this feature is not that easy, since there are a lot of decisions to be made which are equally likely to be a valid usecase and if we don't consider them here, it will probably make them harder to implement later.
To explain, let's take an example collection with 16 items and a page size of 5.
The current behavior:
[1,2,3,4,5], [6,7,8,9,10], [11,12,13,14,15], [16]
The behavior from above:
[1,2,3,4,5], [6,7,8,9,10], [11,12,13,14,15,16]
But another valid one would be to do this (let's say we want at least 3 items on a page):
[1,2,3,4,5], [6,7,8,9,10], [11,12,13], [14,15,16]
Also a balanced option would be valid (calculate the number of pages based on the size and average the items):
[1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16]
All behaviors could be achieved, by optionally replacing the size value in paginations with an object with the following properties:
size: 5, // like current size
min: 3, // minimum number of items per page (if possible)
max: 7, // allows "overfilling" like requested here
distribute: true // distribute the items on the available pages
This could be extended in the future in case it's required. This is also just a first thought and maybe there are even better solutions out there.