create category archive pagination code in gatsby-node.js
const { allContentfulCategory, allContentfulBlogPost } = res.data
// create archive pages for each category
allContentfulCategory.edges.forEach(catEdge => {
// filter out the posts that belongs tot the current category
const filteredPosts = allContentfulBlogPost.edges.filter(
el => el.node.catetory.catSlug === catEdge.node.catSlug
)
if (filteredPosts.length > 0) {
paginate({
createPage,
items: filteredPosts,
itemsPerPage: 3,
component: postListCatTemplate,
pathPrefix: `/blog/${catEdge.node.catSlug}`,
context: {
catId: catEdge.node.id,
catName: catEdge.node.Title,
catSlug: catEdge.node.catSlug,
catCount: catEdge.node.count,
categories: allContentfulCategory.edges,
},
})
}
})