Skip to content

Instantly share code, notes, and snippets.

@danilowoz
Created April 28, 2019 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danilowoz/d431b2bf814ded875e7f3d2af3235628 to your computer and use it in GitHub Desktop.
Save danilowoz/d431b2bf814ded875e7f3d2af3235628 to your computer and use it in GitHub Desktop.
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