-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
120 lines (104 loc) · 2.71 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
const path = require("path")
exports.onCreateNode = ({ node, actions }) => {
const { createNodeField } = actions
if (node.internal.type === `googleSheetMasterRow`) {
const tags = node.tag ? node.tag.split(', ') : []
createNodeField({
name: `tags`,
node,
value: tags
})
}
}
exports.createPages = async ({ actions, graphql, reporter }) => {
const { createPage } = actions
const channelTemplate = path.resolve("src/templates/channel.js")
const durationTemplate = path.resolve("src/templates/duration.js")
const tagTemplate = path.resolve("src/templates/tag.js")
const levelTemplate = path.resolve("src/templates/level.js")
const typeTemplate = path.resolve("src/templates/type.js")
const result = await graphql(`
{
channelGroup: allGoogleSheetMasterRow {
distinct(field: channel)
}
durationGroup: allGoogleSheetMasterRow {
distinct(field: duration)
}
tagGroup: allGoogleSheetMasterRow {
distinct(field: fields___tags)
}
levelGroup: allGoogleSheetMasterRow {
distinct(field: level)
}
typeGroup: allGoogleSheetMasterRow {
distinct(field: yogatype)
}
}
`)
// handle errors
if (result.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`)
return
}
// Extract channels data from query
const channels = result.data.channelGroup.distinct
// Make channels pages
channels.forEach(channel => {
createPage({
path: `/channel/${channel}/`,
component: channelTemplate,
context: {
channel: channel,
},
})
})
// Extract duration data from query
const durations = result.data.durationGroup.distinct
// Make duration pages
durations.forEach(duration => {
createPage({
path: `/duration/${duration}/`,
component: durationTemplate,
context: {
duration: parseInt(duration),
},
})
})
// Extract tag data from query
const tags = result.data.tagGroup.distinct
// Make tag pages
tags.forEach(tag => {
createPage({
path: `/tag/${tag}/`,
component: tagTemplate,
context: {
tag: tag,
},
})
})
// Extract level data from query
const levels = result.data.levelGroup.distinct
// Make level pages
levels.forEach(level => {
createPage({
path: `/level/${level}/`,
component: levelTemplate,
context: {
level: parseInt(level),
},
})
})
// Extract yogaType data from query
const types = result.data.typeGroup.distinct
// Make yogaType pages
types.forEach(type => {
createPage({
path: `/type/${type}/`,
component: typeTemplate,
context: {
type: type,
},
})
})
}