DEV Community

Discussion on: Add pagination for dynamic data in Eleventy

Collapse
 
bayuangora profile image
Bayu Angora • Edited

Every single post is works. But I always got an error in pagination.

Please check or fork my repo here ->
github.com/BayuAngora/11ty

Thread Thread
 
gabbersepp profile image
Josef Biehler

Hi, thanks! I will try it out until tomorrow :-)

Thread Thread
 
bayuangora profile image
Bayu Angora

Thanks, Josef. I hope it's fixed.

Thread Thread
 
gabbersepp profile image
Josef Biehler

Sorry for the late reply. I had to fix some other problems. I made a pull request and added some comments in the message: github.com/BayuAngora/11ty/pull/1

Your mentioned problem exists because you wanted to have a permalink for /blog/index.md. But the index.md file is duplicated due to the usage of pagination. So you can't tell eleventy to use permalink /blog.html for all those duplicates. To fix this, I have included "pagination.pageNumber" in the permalink and adjusted the index.html to link to "/blog/page-0.html".

See this:
11ty.dev/docs/pagination/#remappin...

Thread Thread
 
bayuangora profile image
Bayu Angora

Instead of adding 0 into permalink, I rather use this ->

blog/{% if pagination.pageNumber > 0 %}{{ pagination.pageNumber | plus: 1 }}/{% endif %}index.html

And everything is fixed now. Thank you so much, Josef.