Replace node.fields.link with node.path as it's now included with gatsby-source-wordpress

This commit is contained in:
ponas committed 2019-03-03 13:38:02 +01:00
1 parent 43207b7b6e
commit ba95006c17
5 files changed
+29 -58

No files matched your search

+17 -35
View File
@@ -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,
})
}
}
+3 -10
View File
@@ -10,17 +10,12 @@ export default class AssociationList extends React.Component {
{association.featured_media && association.featured_media.localFile && (
<div className="association-image">
<Img
fluid={
association.featured_media.localFile.childImageSharp.fluid
}
fluid={association.featured_media.localFile.childImageSharp.fluid}
/>
</div>
)}
<div className="association-text">
<Link
to={association.fields.link}
key={association.id}
>
<Link to={association.path} key={association.id}>
<h2 className="association-title">{association.title}</h2>
</Link>
@@ -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
}
}
`
+3 -7
View File
@@ -67,7 +67,7 @@ export default class EventList extends React.Component {
renderEvent(event) {
return (
<Link to={event.fields.link} className="event" key={event.id}>
<Link to={event.path} className="event" key={event.id}>
<div className="event-image">
{event.featured_media && event.featured_media.localFile && (
<Img fluid={event.featured_media.localFile.childImageSharp.fluid} />
@@ -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
}
`
+2 -4
View File
@@ -12,7 +12,7 @@ export default class PostList extends React.Component {
<h1 className="section-title">{title}</h1>
<div className="post-list">
{posts.map(({ node: post }) => (
<Link to={post.fields.link} className="post" key={post.id}>
<Link to={post.path} className="post" key={post.id}>
{post.featured_media && post.featured_media.localFile && (
<div className="post-image">
<Img
@@ -49,6 +49,7 @@ PostList.propTypes = {
export const pageQuery = graphql`
fragment PostListFields on wordpress__POST {
id
path
title
excerpt
author {
@@ -59,9 +60,6 @@ export const pageQuery = graphql`
}
}
date(formatString: "MMMM DD, YYYY")
fields {
link
}
featured_media {
localFile {
...FluidImage
+4 -2
View File
@@ -82,7 +82,7 @@ export const EventTemplate = ({
<ul>
{eventTypes.map(type => (
<li key={`${type.slug}`}>
<Link to={type.fields.link}>{type.name}</Link>
<Link to={type.path}>{type.name}</Link>
</li>
))}
</ul>
@@ -96,7 +96,7 @@ export const EventTemplate = ({
</div>
)}
</div>
<div
<div
className="event-content"
dangerouslySetInnerHTML={{ __html: content }}
/>
@@ -148,6 +148,8 @@ export const eventQuery = graphql`
query EventByID($id: String!) {
wordpressWpEvents(id: { eq: $id }) {
id
link
path
title
slug
content