forked from nextflow-io/summit-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
313 lines (284 loc) · 7.6 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
const path = require('path');
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions;
const typeDefs = [
`
type MetaFields implements Node {
title: String
description: String
image: File @fileByRelativePath
}
`,
`
type People implements Node {
name: String!
position: String!
email: String
image: File @fileByRelativePath
content: Mdx
tags: [String]
meta: MetaFields
}
`,
`
type Event implements Node {
slug: String
title: String
description: String
datetime: Date @dateformat
date: String
time: String
timeframe: String
speakers: [People] @link(by: "name")
events: [Event] @link(by: "slug")
isChild: Boolean
hasPage: Boolean
location: String
locationUrl: String
youtube: String
youtubeUrl: String
tags: [String]
meta: MetaFields
content: Mdx
}
`,
`
type Accommodation implements Node {
title: String
image: File @fileByRelativePath
stars: Int
url: String
walkingTime: String
breakfast: Boolean
adultOne: String
adultsTwo: String
tax: String
promotionCode: String
content: Mdx
}
`,
`
type Poster implements Node {
slug: String
title: String
url: String
image: File @fileByRelativePath
poster: File @fileByRelativePath
speakers: [People] @link(by: "name")
tags: [String]
meta: MetaFields
content: Mdx
}
`,
];
createTypes(typeDefs);
};
exports.onCreateNode = ({ node, actions, getNode, createNodeId, createContentDigest }) => {
const { createNodeField, createNode } = actions;
if (node.internal.type === 'Mdx') {
const parent = getNode(node.parent);
if (parent.internal.type === 'File') {
createNodeField({
name: 'sourceName',
node,
value: parent.sourceInstanceName,
});
}
if (parent.internal.type === 'File' && parent.sourceInstanceName === 'people') {
const content = {
slug: node.frontmatter.slug,
name: node.frontmatter.name,
email: node.frontmatter.email,
position: node.frontmatter.position,
image: node.frontmatter.image,
github: node.frontmatter.github,
twitter: node.frontmatter.twitter,
linkedin: node.frontmatter.linkedin,
tags: node.frontmatter.tags || [],
meta: node.frontmatter.meta,
content: node,
};
createNode({
id: createNodeId(`people-${node.id}`),
parent: node.id,
children: [],
internal: {
type: 'People',
contentDigest: createContentDigest(content),
},
...content,
});
}
if (parent.internal.type === 'File' && parent.sourceInstanceName === 'events') {
const content = {
slug: node.frontmatter.slug,
title: node.frontmatter.title,
description: node.frontmatter.description,
datetime: node.frontmatter.datetime,
date: node.frontmatter.date,
time: node.frontmatter.time,
timeframe: node.frontmatter.timeframe,
events: node.frontmatter.events,
isChild: node.frontmatter.isChild,
speakers: node.frontmatter.speakers,
location: node.frontmatter.location,
locationUrl: node.frontmatter.locationUrl,
youtube: node.frontmatter.youtube,
youtubeUrl: node.frontmatter.youtubeUrl,
hasPage: node.frontmatter.hasPage,
tags: node.frontmatter.tags,
meta: node.frontmatter.meta,
content: node,
};
createNode({
id: createNodeId(`event-post-${node.id}`),
parent: node.id,
children: [],
internal: {
type: 'Event',
contentDigest: createContentDigest(content),
},
...content,
});
}
if (parent.internal.type === 'File' && parent.sourceInstanceName === 'accommodations') {
const content = {
title: node.frontmatter.title,
image: node.frontmatter.image,
stars: node.frontmatter.stars,
url: node.frontmatter.url,
walkingTime: node.frontmatter.walkingTime,
breakfast: node.frontmatter.breakfast,
adultOne: node.frontmatter.adultOne,
adultsTwo: node.frontmatter.adultsTwo,
tax: node.frontmatter.tax,
promotionCode: node.frontmatter.promotionCode,
content: node,
};
createNode({
id: createNodeId(`accommodation-post-${node.id}`),
parent: node.id,
children: [],
internal: {
type: 'Accommodation',
contentDigest: createContentDigest(content),
},
...content,
});
}
if (parent.internal.type === 'File' && parent.sourceInstanceName === 'posters') {
const content = {
slug: node.frontmatter.slug,
title: node.frontmatter.title,
image: node.frontmatter.image,
poster: node.frontmatter.poster,
poster_id: node.frontmatter.poster_id,
url: node.frontmatter.url,
speakers: node.frontmatter.speakers,
tags: node.frontmatter.tags,
meta: node.frontmatter.meta,
content: node,
};
createNode({
id: createNodeId(`poster-post-${node.id}`),
parent: node.id,
children: [],
internal: {
type: 'Poster',
contentDigest: createContentDigest(content),
},
...content,
});
}
}
};
exports.createPages = async ({ graphql, actions, reporter }) => {
const { createPage, createRedirect } = actions;
const eventTemplate = path.resolve('src/templates/event.jsx');
const speakerTemplate = path.resolve('src/templates/speaker.jsx');
const posterTemplate = path.resolve('src/templates/poster.jsx');
const result = await graphql(`
{
speakers: allPeople {
nodes {
slug
}
}
events: allEvent {
nodes {
slug
hasPage
}
}
posters: allPoster {
nodes {
slug
}
}
}
`);
if (result.errors) {
rporter.panicOnBuild('Build failed while running GraphQL query');
return;
}
const speakers = result.data.speakers.nodes;
speakers.forEach((speaker) => {
createPage({
path: speaker.slug,
component: speakerTemplate,
context: {
slug: speaker.slug,
},
});
});
const events = result.data.events.nodes;
events.forEach((event) => {
if (event.hasPage) {
createPage({
path: `/program/${event.slug}/`,
component: eventTemplate,
context: {
slug: event.slug,
}
});
}
});
const posters = result.data.posters.nodes;
posters.forEach((poster) => {
createPage({
path: `/posters/${poster.slug}/`,
component: posterTemplate,
context: {
slug: poster.slug,
}
});
});
};
exports.onCreatePage = async ({ page, actions }) => {
const { createPage, deletePage } = actions
if (page.path.match(/^\/summit-2023-preregistration/)) {
deletePage(page)
const pageContext = {
layout: "Plain",
}
createPage({
...page,
context: {
...page.context,
...pageContext,
},
})
}
}
exports.onCreateWebpackConfig = ({ actions, loaders }) => {
actions.setWebpackConfig({
module: {
rules: [
{
test: /\.jsx$/,
use: [loaders.js()],
},
],
},
});
};