Created
April 28, 2019 19:57
-
-
Save danilowoz/d431b2bf814ded875e7f3d2af3235628 to your computer and use it in GitHub Desktop.
Getting the categories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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