Skip to content

Instantly share code, notes, and snippets.

@rubenRP
Created April 27, 2020 07:28

Revisions

  1. rubenRP created this gist Apr 27, 2020.
    29 changes: 29 additions & 0 deletions gatsby-generation.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    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
    })

    ...