Created
September 10, 2020 05:11
-
-
Save AbmSourav/03a879c31adf78a3e6ce15dac65757f2 to your computer and use it in GitHub Desktop.
Dynamic pages with GatsbyJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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