-
Notifications
You must be signed in to change notification settings - Fork 2
/
gatsby-node.js
72 lines (62 loc) · 1.81 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
import themes from "./src/data/themes"
import colors from "./src/data/colors"
import environments from "./src/data/environments"
function sourceNodes({ actions, createNodeId, createContentDigest }) {
themes
.sort(() => Math.random() - 0.5)
.forEach(theme => {
const nodeMeta = {
id: createNodeId(`theme-${theme.name}`),
parent: null,
children: [],
internal: {
type: `Theme`,
mediaType: `text/html`,
content: JSON.stringify(theme),
contentDigest: createContentDigest(theme),
},
}
actions.createNode({ ...theme, ...nodeMeta })
})
Object.keys(colors).forEach(key => {
const nodeMeta = {
id: createNodeId(`color-${colors[key].name}`),
parent: null,
children: [],
internal: {
type: `ColorblindnessType`,
mediaType: `text/html`,
content: JSON.stringify(colors[key]),
contentDigest: createContentDigest(colors[key]),
},
}
actions.createNode({ ...colors[key], ...nodeMeta })
})
Object.keys(environments)
.sort((a, b) => {
const envA = environments[a].name
const envB = environments[b].name
if (envA.toLowerCase() > envB.toLowerCase()) {
return 1
}
if (envB.toLowerCase() > envA.toLowerCase()) {
return -1
}
return 0
})
.forEach(key => {
const nodeMeta = {
id: createNodeId(`environment-${environments[key].name}`),
parent: null,
children: [],
internal: {
type: `Environment`,
mediaType: `text/html`,
content: JSON.stringify(environments[key]),
contentDigest: createContentDigest(environments[key]),
},
}
actions.createNode({ ...environments[key], ...nodeMeta })
})
}
export { sourceNodes }