Skip to content

Instantly share code, notes, and snippets.

@rubenRP
Created April 27, 2020 07:28
Show Gist options
  • Save rubenRP/035cbf14e303d55188968f77cf070afd to your computer and use it in GitHub Desktop.
Save rubenRP/035cbf14e303d55188968f77cf070afd to your computer and use it in GitHub Desktop.
posts.forEach((post, index) => {
const previous = index === posts.length - 1 ? null : posts[index + 1].node
const next = index === 0 ? null : posts[index - 1].node
const path = post.node.fileAbsolutePath
const regex = "/blog/"
if (path.match(regex)) {
createPage({
path: `blog${post.node.fields.slug}`,
component: blogPost,
context: {
slug: post.node.fields.slug,
previous,
next,
},
})
} else {
createPage({
path: `${post.node.fields.slug}`,
component: defaultPage,
context: {
slug: post.node.fields.slug,
},
})
}
// return null
})
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment