Add associations
This commit is contained in:
1 parent
47375e6400
commit
a2e5aa2e6f
6 files changed
+255
-8
No files matched your search
+61
-5
@@ -198,6 +198,60 @@ exports.createPages = ({ actions, graphql }) => {
|
||||
}
|
||||
)
|
||||
})
|
||||
.then(() => {
|
||||
return graphql(`
|
||||
{
|
||||
allWordpressWpAssociations {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
slug
|
||||
status
|
||||
fields {
|
||||
link
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`)
|
||||
})
|
||||
.then(result => {
|
||||
if (result.errors) {
|
||||
result.errors.forEach(e => console.error(e.toString()))
|
||||
return Promise.reject(result.errors)
|
||||
}
|
||||
|
||||
const associationTemplate = path.resolve(`./src/templates/association.js`)
|
||||
|
||||
// In production builds, filter for only published associations.
|
||||
const allAssociations = result.data.allWordpressWpAssociations.edges
|
||||
const associations =
|
||||
process.env.NODE_ENV === 'production'
|
||||
? getOnlyPublished(allAssociations)
|
||||
: allAssociations
|
||||
|
||||
// Iterate over the array of associations
|
||||
_.each(associations, ({ node: association }) => {
|
||||
// Create the Gatsby page for this WordPress event
|
||||
createPage({
|
||||
path: association.fields.link,
|
||||
component: associationTemplate,
|
||||
context: {
|
||||
id: association.id,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
// Create the list of associations
|
||||
const associationListTemplate = path.resolve(
|
||||
`./src/templates/association-list.js`
|
||||
)
|
||||
createPage({
|
||||
path: `/foreningene/`,
|
||||
component: associationListTemplate,
|
||||
})
|
||||
})
|
||||
.then(() => {
|
||||
return graphql(`
|
||||
{
|
||||
@@ -315,11 +369,13 @@ exports.onCreateNode = ({ node, actions, getNode }) => {
|
||||
})
|
||||
}
|
||||
|
||||
if (
|
||||
node.internal.type === 'wordpress__POST' ||
|
||||
node.internal.type === 'wordpress__wp_events' ||
|
||||
node.internal.type === 'wordpress__wp_event_types'
|
||||
) {
|
||||
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,
|
||||
|
||||
Reference in new issue
Block a user