GatsbyCentral / gatsby-awesome-pagination

An opinionated, more awesome approach to pagination in Gatsby
MIT License
109 stars 27 forks source link

How To Paginate First Page Differently #6

Closed ryanwiemer closed 6 years ago

ryanwiemer commented 6 years ago

@chmac ,

Do you have any thoughts on how to achieve a different number of posts on the first page vs other paginated pages? In a perfect world it would be an additional option such as itemsPerFirstPage.

It's pretty common to see something like the home page with a smaller number of posts while the paginated pages show more. So for example 3 posts on the homepage but then 9 posts per subsequent paginated page.

chmac commented 6 years ago

Oooh, super interesting use case. Hadn't thought at all about that. I'm open to adding such an option. It will add a little complexity I think, I'll contemplate on it a few days and see what comes up.

ryanwiemer commented 6 years ago

@chmac Sounds good!

In case it's helpful I was able to achieve the desired functionality albeit I had to do the pagination logic manually without the plugin. It's a little messy but it works:

chmac commented 6 years ago

@ryanwiemer Thanks. That’s definitely helpful. I was thinking of calculating the number of pages with slightly different logic, and then doing something like limit = page === 0 ? postsPerFirstPage : postsPerPage. Will contemplate further and get back next week.

ryanwiemer commented 6 years ago

Cool. Yeah, I'm sure there are better ways to simplify the logic. Like I said it's a little messy right now. 😉

chmac commented 6 years ago

@ryanwiemer Had a quick crack at this. It looks like the changeset is quite small. I haven't tested this yet, but will try to do that this week / next, and if it all looks good, release it. Any feedback on the commit above would be greatly appreciated. :-)

chmac commented 6 years ago

@ryanwiemer Wow, it's more complicated than I first though. I forgot to update the $skip parameter. I think I've covered that now and I've done some light testing. But will let this sit for a few days and look at it again before releasing.

ryanwiemer commented 6 years ago

@chmac,

Awesome! I think this will be a very useful feature. Let me know once you are ready to officially release it. I would love to use your plugin on my gatsby-starter rather than do all the logic manually in the gatsby-node.js file. Your approach to pagination definitely resonates with me more than the other plugins out there today. 👍

chmac commented 6 years ago

It's out as v 0.3.0. I forgot to look at your bug in #7 before releasing. Will do that now.