Skip to content

Instantly share code, notes, and snippets.

@rubenRP
Created April 27, 2020 07:27
Show Gist options
  • Save rubenRP/e0f23cacb426724676f1e5100905b19e to your computer and use it in GitHub Desktop.
Save rubenRP/e0f23cacb426724676f1e5100905b19e to your computer and use it in GitHub Desktop.
// Create pages and blog posts.
const posts = result.data.pagesGroup.edges
const postsPerPage = 10
const numPages = Math.ceil(posts.length / postsPerPage)
Array.from({ length: numPages }).forEach((_, i) => {
createPage({
path: i === 0 ? `/blog` : `/blog/page:${i + 1}`,
component: blogPage,
context: {
limit: postsPerPage,
skip: i * postsPerPage,
numPages,
currentPage: i + 1,
},
})
})
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment