Skip to content

Instantly share code, notes, and snippets.

@AbmSourav
Created September 10, 2020 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbmSourav/03a879c31adf78a3e6ce15dac65757f2 to your computer and use it in GitHub Desktop.
Save AbmSourav/03a879c31adf78a3e6ce15dac65757f2 to your computer and use it in GitHub Desktop.
Dynamic pages with GatsbyJS
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const wpData = await graphql(`
{
allWordpressPost {
nodes {
wordpress_id
slug
title
content
author {
name
}
}
}
}
`)
if (wpData.errors) {
console.error(wpData.errors)
}
const { allWordpressPost } = wpData.data
allWordpressPost.nodes.forEach( post => {
createPage({
path: `/${post.slug}`,
component: require.resolve(`./src/templates/post.js`),
context: { post },
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment