Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Getting the categories
const kebabCase = require(`lodash.kebabcase`)
const allCategories = Object.keys(countCategories)
allCategories.forEach((cat, i) => {
const link = `/blog/category/${kebabCase(cat)}`
Array.from({
length: Math.ceil(countCategories[cat] / postsPerPage),
}).forEach((_, i) => {
createPage({
path: i === 0 ? link : `${link}/page/${i + 1}`,
component: blogCategoryLayout,
context: {
allCategories: allCategories,
category: cat,
limit: postsPerPage,
skip: i * postsPerPage,
currentPage: i + 1,
numPages: Math.ceil(countCategories[cat] / postsPerPage),
},
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment