From ba95006c17eb810335c0f902502737cb8f7aa073 Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Sun, 3 Mar 2019 13:38:02 +0100 Subject: [PATCH] Replace node.fields.link with node.path as it's now included with gatsby-source-wordpress --- gatsby-node.js | 52 ++++++++++--------------------- src/components/AssociationList.js | 13 ++------ src/components/EventList.js | 10 ++---- src/components/PostList.js | 6 ++-- src/templates/event.js | 6 ++-- 5 files changed, 29 insertions(+), 58 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index 4ae3364..81f9f2e 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -15,6 +15,7 @@ exports.createPages = ({ actions, graphql }) => { edges { node { id + path slug status } @@ -41,9 +42,13 @@ exports.createPages = ({ actions, graphql }) => { : allPages // Call `createPage()` once per WordPress page + const ignoreSlugs = ['program', 'foreningene'] _.each(pages, ({ node: page }) => { + if (ignoreSlugs.includes(page.slug)) { + return + } createPage({ - path: `/${page.slug}/`, + path: `/${page.path}/`, component: pageTemplate, context: { id: page.id, @@ -58,11 +63,9 @@ exports.createPages = ({ actions, graphql }) => { edges { node { id + path slug status - fields { - link - } } } } @@ -89,7 +92,7 @@ exports.createPages = ({ actions, graphql }) => { _.each(posts, ({ node: post }) => { // Create the Gatsby page for this WordPress post createPage({ - path: post.fields.link, + path: post.path, component: postTemplate, context: { id: post.id, @@ -114,11 +117,9 @@ exports.createPages = ({ actions, graphql }) => { edges { node { id + path slug status - fields { - link - } } } } @@ -144,7 +145,7 @@ exports.createPages = ({ actions, graphql }) => { _.each(events, ({ node: event }) => { // Create the Gatsby page for this WordPress event createPage({ - path: event.fields.link, + path: event.path, component: eventTemplate, context: { id: event.id, @@ -174,11 +175,9 @@ exports.createPages = ({ actions, graphql }) => { edges { node { id + path name slug - fields { - link - } } } } @@ -195,13 +194,13 @@ exports.createPages = ({ actions, graphql }) => { _.each( result.data.allWordpressWpEventTypes.edges, - ({ node: event_type }) => { + ({ node: eventType }) => { createPage({ - path: event_type.fields.link, + path: eventType.path, component: eventTypeTemplate, context: { - name: event_type.name, - slug: event_type.slug, + name: eventType.name, + slug: eventType.slug, }, }) } @@ -214,11 +213,9 @@ exports.createPages = ({ actions, graphql }) => { edges { node { id + path slug status - fields { - link - } } } } @@ -244,7 +241,7 @@ exports.createPages = ({ actions, graphql }) => { _.each(associations, ({ node: association }) => { // Create the Gatsby page for this WordPress event createPage({ - path: association.fields.link, + path: association.path, component: associationTemplate, context: { id: association.id, @@ -377,19 +374,4 @@ exports.onCreateNode = ({ node, actions, getNode }) => { value, }) } - - relativeLinksFor = [ - 'wordpress__POST', - 'wordpress__wp_associations', - 'wordpress__wp_events', - 'wordpress__wp_event_types', - ] - if (relativeLinksFor.includes(node.internal.type)) { - const link = new URL(node.link).pathname - createNodeField({ - node, - name: `link`, - value: link, - }) - } } diff --git a/src/components/AssociationList.js b/src/components/AssociationList.js index e4def82..888457e 100644 --- a/src/components/AssociationList.js +++ b/src/components/AssociationList.js @@ -10,17 +10,12 @@ export default class AssociationList extends React.Component { {association.featured_media && association.featured_media.localFile && (
)}
- +

{association.title}

@@ -57,6 +52,7 @@ AssociationList.propTypes = { export const pageQuery = graphql` fragment AssociationListFields on wordpress__wp_associations { id + path title excerpt featured_media { @@ -64,8 +60,5 @@ export const pageQuery = graphql` ...FluidImage } } - fields { - link - } } ` diff --git a/src/components/EventList.js b/src/components/EventList.js index c2e06d1..1eec79a 100644 --- a/src/components/EventList.js +++ b/src/components/EventList.js @@ -67,7 +67,7 @@ export default class EventList extends React.Component { renderEvent(event) { return ( - +
{event.featured_media && event.featured_media.localFile && ( @@ -131,13 +131,12 @@ export const pageQuery = graphql` event_types { name slug - fields { - link - } + path } } fragment EventListFields on wordpress__wp_events { id + path title start_time end_time @@ -146,9 +145,6 @@ export const pageQuery = graphql` ...FluidImage } } - fields { - link - } ...EventTypeFields } ` diff --git a/src/components/PostList.js b/src/components/PostList.js index 8dab55a..d242d56 100644 --- a/src/components/PostList.js +++ b/src/components/PostList.js @@ -12,7 +12,7 @@ export default class PostList extends React.Component {

{title}

{posts.map(({ node: post }) => ( - + {post.featured_media && post.featured_media.localFile && (
{eventTypes.map(type => (
  • - {type.name} + {type.name}
  • ))} @@ -96,7 +96,7 @@ export const EventTemplate = ({
    )}
    -
    @@ -148,6 +148,8 @@ export const eventQuery = graphql` query EventByID($id: String!) { wordpressWpEvents(id: { eq: $id }) { id + link + path title slug content