Permalink
Browse files

Add completed workshop code.

  • Loading branch information...
crgeary committed Aug 16, 2018
1 parent 1d04556 commit 12ea9c2d5c343c29460dbcc5d430c9f3ae681105
Showing with 70 additions and 13 deletions.
  1. +40 −5 gatsby-node.js
  2. +0 −8 src/pages/index.js
  3. +30 −0 src/templates/page.js
@@ -12,7 +12,20 @@ const queryWordPressGatsbyConfig = `
}
`
// step 1. add graphql query for wp pages here
const queryWordPressPages = `
{
allWordpressPage (filter: { status: { eq : "publish" } }) {
edges {
node {
id
wordpress_id
slug
template
}
}
}
}
`
exports.createPages = ({ graphql, boundActionCreators }) => {
@@ -32,10 +45,32 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
.then(config => {
// step 2. query for wordpress pages, and then loop over them
// when adding step 4, please remove the resolve(); function below.
resolve();
return graphql(queryWordPressPages).then(r => {
if (r.errors) {
console.log(r.errors);
reject(r.errors);
}
_.each(r.data.allWordpressPage.edges, edge => {
createPage({
path: edge.node.wordpress_id === config.front_page ? '/' : edge.node.slug,
component: (
() => {
if (edge.node.wordpress_id === config.front_page) {
return slash(path.resolve(`./src/templates/home.js`));
}
return slash(path.resolve(`./src/templates/page.js`));
}
)(),
context: {
id: edge.node.id,
wordpress_id: edge.node.wordpress_id
}
});
});
})
.then(r => {
resolve();
});
});

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,30 @@
import React, { Component } from 'react';
import BaseLayout from '../components/Layouts/BaseLayout';
export default class PageTemplate extends Component {
render() {
const { page, config } = this.props.data;
return (
<BaseLayout config={config} hero={{ image: page.hero, title: page.title }}>
<div dangerouslySetInnerHTML={{ __html: page.content }} />
</BaseLayout>
);
}
}
export const query = graphql`
query currentPage($id: String!) {
page: wordpressPage(id: { eq: $id }) {
title
content
hero: featured_media {
...HeroImage
}
}
config: wordpressGatsbyConfig {
name
description
}
}
`

0 comments on commit 12ea9c2

Please sign in to comment.