-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
202 lines (180 loc) · 5.08 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
const path = require("path");
const park = process.env.GATSBY_PARK;
// const { createRemoteFileNode } = require(`gatsby-source-filesystem`);
async function createAllPages(createPage, pageTemplate, articleTemplate, informationTemplate, postTemplate, graphql) {
const result = await graphql(
`
query($park: String!) {
pages: allNodePage(
filter: {
field_site: { drupal_internal__target_id: { eq: $park } }
path: { alias: { ne: null } }
}
) {
nodes {
drupalId: drupal_id
path {
alias
}
body {
value
}
}
}
articles: allNodeArticle(
filter: {
field_site: { drupal_internal__target_id: { eq: $park } }
path: { alias: { ne: null } }
}
) {
nodes {
drupalId: drupal_id
path {
alias
}
body {
value
}
}
}
infos: allNodeInformation(
filter: {
field_site: { drupal_internal__target_id: { eq: $park } }
path: { alias: { ne: null } }
}
) {
nodes {
drupalId: drupal_id
path {
alias
}
body {
value
}
}
}
posts: allNodePost(
filter: {
field_site: { drupal_internal__target_id: { eq: $park } }
path: { alias: { ne: null } }
}
) {
nodes {
drupalId: drupal_id
path {
alias
}
body {
value
}
}
}
}
`,
{ park }
);
result.data.pages.nodes.forEach((node) => {
let path = node.path.alias.replace(`/${park}`, "");
if (path == "") {
path = "/";
}
createPage({
path,
component: pageTemplate,
context: {
park:`${park}`,
drupalId: node.drupalId,
},
});
});
result.data.articles.nodes.forEach((node) => {
let path = node.path.alias.replace(`/${park}`, "");
if (path == "") {
path = "/";
}
createPage({
path,
component: articleTemplate,
context: {
park:`${park}`,
drupalId: node.drupalId,
},
});
});
result.data.infos.nodes.forEach((node) => {
let path = node.path.alias.replace(`/${park}`, "");
if (path == "") {
path = "/";
}
createPage({
path,
component: informationTemplate,
context: {
park:`${park}`,
drupalId: node.drupalId,
},
});
});
result.data.posts.nodes.forEach((node) => {
let path = node.path.alias.replace(`/${park}`, "");
if (path == "") {
path = "/";
}
createPage({
path,
component: postTemplate,
context: {
park:`${park}`,
drupalId: node.drupalId,
},
});
});
};
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const pageTemplate = path.resolve(`src/templates/page.tsx`);
const articleTemplate = path.resolve(`src/templates/article.tsx`)
const informationTemplate = path.resolve(`src/templates/information.tsx`)
const postTemplate = path.resolve(`src/templates/post.tsx`);
await createAllPages(createPage, pageTemplate, articleTemplate, informationTemplate, postTemplate, graphql);
};
// exports.onCreateNode = async ({
// node,
// actions: { createNode, createNodeField },
// store,
// cache,
// createNodeId,
// reporter
// }) => {
// // if (node.internal.type === `node__page`) {
// // const slug = node.drupal_id;
// // createNodeField({
// // node,
// // name: `slug`,
// // value: slug
// // });
// // }
// // For all nodes that have a file which hasn't been downloaded, call createRemoteFileNode
// // if (node.internal.type === "file__file" && node.localFile !== null) {
// if (node.internal.type === "file__file") {
// const url = node.uri.url;
// try {
// const fileNode = await createRemoteFileNode({
// url, // string that points to the URL of the image
// parentNodeId: node.id, // id of the parent node of the fileNode you are going to create
// createNode, // helper function in gatsby-node to generate the node
// createNodeId, // helper function in gatsby-node to generate the node id
// cache, // Gatsby's cache
// store, // Gatsby's redux store
// reporter // Gatsby's reporter
// });
// // if the file was created, attach the new node to the parent node
// if (fileNode) {
// node.localFile___NODE = fileNode.id;
// }
// } catch (error) {
// // If you are depending on the localfile existing in page queries, then a hard error might be preferable to stop Gatsby from
// reporter.warn(error);
// }
// }
// }