Permalink
Browse files

Pull in WordPress Pages

  • Loading branch information...
booyaa committed Jan 1, 2019
1 parent 2249ea8 commit ce6cc022a881e813af31279ff857f908ecc599f4
Showing with 61 additions and 2 deletions.
  1. +36 −1 gatsby-node.js
  2. +1 −1 src/components/layout.js
  3. +24 −0 src/templates/page.js
@@ -38,5 +38,40 @@ exports.createPages = ({ graphql, actions }) => {
}) // query.then
}) // createWpPosts

return Promise.all([createWpPosts])
const createWpPages = new Promise((resolve, reject) => {
const query = graphql(`
{
allWordpressPage {
edges {
node {
id
slug
}
}
}
}
`)

query.then(result => {
if (result.errors) {
console.error(result.errors)
reject(result.errors)
}

const pageEdges = result.data.allWordpressPage.edges
pageEdges.forEach(edge => {
createPage({
path: `/${edge.node.slug}`,
component: path.resolve(`./src/templates/page.js`),
context: {
id: edge.node.id,
},
})
})

resolve()
}) // query.then
}) // createWpPages

return Promise.all([createWpPosts, createWpPages])
} // createPages
@@ -29,7 +29,7 @@ const Layout = ({ children }) => (
>
{children}
<footer>
© 2018, Built with <a href="https://www.gatsbyjs.org">Gatsby</a>
© 2018, Built with <a href="https://www.gatsbyjs.org">Gatsby</a> | <a href="/about">About Us</a>
</footer>
</div>
</>
@@ -0,0 +1,24 @@
import React from 'react'
import { graphql } from 'gatsby'
import Layout from '../components/layout'

export default ({ data }) => {
const page = data.wordpressPage
return (
<Layout>
<div>
<h1 dangerouslySetInnerHTML={{ __html: page.title }} />
<div dangerouslySetInnerHTML={{ __html: page.content }} />
</div>
</Layout>
)
}

export const pageQuery = graphql`
query($id: String!) {
wordpressPage(id: { eq: $id }) {
title
content
}
}
`

0 comments on commit ce6cc02

Please sign in to comment.