-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgatsby-node.js
81 lines (77 loc) · 1.95 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
const path = require(`path`);
const sharp = require('sharp');
sharp.simd(false)
sharp.cache(false)
exports.onCreateNode = ({ node, actions }) => {
const { createNodeField } = actions;
if (node.internal.type === `Airtable` && node.table === `Speakers`) {
const slug =
"/speakers/" + node.data.anchor
createNodeField({
node,
name: `slug`,
value: slug
});
}
if (node.internal.type === `Airtable` && node.table === `Sessions`) {
const slug =
"/sessions/" + node.data.anchor_truncated
createNodeField({
node,
name: `slug`,
value: slug
});
}
};
exports.createPages = ({ actions, graphql }) => {
const { createPage } = actions;
// Go get the data that satisfy
return graphql(
`
query {
speakers: allAirtable(filter: { table: { eq: "Speakers" } }) {
edges {
node {
fields {
slug
}
}
}
}
sessions: allAirtable(filter: { table: { eq: "Sessions" } }) {
edges {
node {
fields {
slug
}
}
}
}
}
`
).then(result => {
// For each node of speaker data
result.data.speakers.edges.forEach(({ node }) => {
createPage({
// Use this path for the page
path: node.fields.slug,
// The template to use for the created pages
component: path.resolve(`./src/templates/the_speaker.js`),
// This allows us to access the variable `slug` in our individual speaker pages
context: {
slug: node.fields.slug
}
});
});
// Create page for each session
result.data.sessions.edges.forEach(({ node }) => {
createPage({
path: node.fields.slug,
component: path.resolve(`./src/templates/the_session.js`),
context: {
slug: node.fields.slug
}
});
});
});
};