This repository has been archived by the owner on Dec 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
74 lines (65 loc) · 1.93 KB
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
// You can delete this file if you're not using it
const path = require(`path`)
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
//const blogPostTemplate = path.resolve(`src/templates/blog-post.js`)
const drupalNodes = await graphql(`
query MyQuery {
__typename
drupaldata {
nodeQuery(
limit: 100
filter: {
conditions: [
{ field: "field_link.uri", operator: IS_NULL }
{ field: "status", value: ["1"] }
]
}
sort: { field: "nid", direction: ASC }
) {
entities {
entityBundle
entityId
entityUrl {
routed
path
... on Drupal_EntityCanonicalUrl {
pathInternal
pathAlias
}
}
}
}
}
}
`)
console.log(JSON.stringify(drupalNodes.data.drupaldata.nodeQuery.entities))
const presentationPostTemplate = path.resolve(
`src/templates/presentationPage.js`
)
const nodeBundlesToTemplates = {
presentation: path.resolve(`src/templates/presentationPage.js`),
blog_post: path.resolve(`src/templates/blogPostPage.js`),
}
drupalNodes.data.drupaldata.nodeQuery.entities.map(entity => {
//drupalNodes.data.drupaldata.nodeQuery.entities.forEach(({ entity }) => {
console.log(JSON.stringify(entity))
const path = entity.entityUrl.path
// const path = "/node/" + entity.entityId
const entityId = entity.entityId
createPage({
path,
component: nodeBundlesToTemplates[entity.entityBundle],
// In your blog post template's graphql query, you can use path
// as a GraphQL variable to query for data from the markdown file.
context: {
entityId,
},
})
})
}