Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Next and prev post
posts.forEach((post, index, arr) => {
post.node.frontmatter.category.forEach(cat => categories.push(cat))
const prev = arr[index - 1]
const next = arr[index + 1]
createPage({
path: post.node.fields.slug,
component: blogLayout,
context: {
slug: post.node.fields.slug,
prev: prev,
next: next,
},
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment