-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.js
192 lines (185 loc) · 4.32 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
const slugify = require('slugify')
const LoadablePlugin = require('@loadable/webpack-plugin')
const ShowTemplate = require.resolve('./src/templates/show.js')
const ShowEmbedTemplate = require.resolve('./src/templates/show-embed.js')
const SongTemplate = require.resolve('./src/templates/song.js')
const VenueTemplate = require.resolve('./src/templates/venue.js')
exports.createSchemaCustomization = ({actions: {createTypes}}) => {
// n.b. this is GraphQL "SDL"
createTypes(`
type guestsCsv implements Node {
instrument: String
name: String
shows: String
sortVal: String
}
type recordingsCsv implements Node {
show: showsCsv @link
type: String
url: String
}
type setsCsv implements Node {
setlist: String
}
type showsCsv implements Node {
date: Date
encore1: Int
encore2: Int
event: String
links: String
notes: String
num_recordings: Int
set1: Int
set2: Int
set3: Int
soundcheck: Int
tagline: String
venue_id: String
}
type songperformancesCsv implements Node {
next_perfid: songperformancesCsv @link
prev_perfid: songperformancesCsv @link
prev_show_id: showsCsv @link
show_id: showsCsv @link
song_id: songsCsv @link
song_name: String
stars: Int
variation: String
}
type songsCsv implements Node {
abbrev: String
author: String
core_jrad: Boolean
core_gd: Boolean
cover_gd: Boolean
performances: String
performed: [songperformancesCsv]
suite: String
teased: [teasesCsv]
title: String!
}
type teasesCsv implements Node {
by: String
notes: String
performance_id: String
song_id: String
song_name: String
within: String
}
type venuesCsv implements Node {
capacity: Int
generic_name: String
location: String
name: String
tagname: String
}
`)
}
exports.createPages = async ({graphql, actions: {createPage, createTypes} }) => {
const result = await graphql(`
query Everything {
allVenuesCsv {
nodes {
id
name
location
capacity
generic_name
tagname
}
}
allSongsCsv {
nodes {
author
core_gd
core_jrad
cover_gd
id
performances
suite
title
}
}
allShowsCsv {
nodes {
date
encore1
encore2
event
id
links
notes
num_recordings
set1
set2
set3
soundcheck
tagline
venue_id
}
}
}
`)
const {
allShowsCsv: {nodes: shows},
allSongsCsv: {nodes: songs},
allVenuesCsv: {nodes: venues},
} = result.data
const lastShowId = Math.max(...shows.map(show => show.id)) // TODO pull this with graphql
shows.filter(show => show.date).forEach((show) => {
createPage({
path: `/show/embed/${show.id}`,
component: ShowEmbedTemplate,
context: {
showId: show.id,
venueId: show.venue_id,
},
}); // semicolon needed to separate the two calls to `createPage`
createPage({
path: `/show/${show.id}`,
component: ShowTemplate,
context: {
showId: show.id,
venueId: show.venue_id,
lastShowId,
}
})
})
songs.filter(song => song.title && song.title !== '[unknown]').forEach((song) => {
createPage({
path: `/song/${song.id}`,
component: SongTemplate,
context: {
songId: song.id,
}
})
})
venues.filter(venue => venue.name).forEach(venue => {
createPage({
path: `/venue/${venue.id}-${slugify(venue.name)}`,
component: VenueTemplate,
context: {
venueId: venue.id,
},
})
})
}
exports.onCreateWebpackConfig = ({ actions, stage }) => {
if (
stage === "build-javascript" ||
stage === "develop" ||
stage === "develop-html"
) {
actions.setWebpackConfig({
plugins: [
new LoadablePlugin({
filename:
stage === "develop"
? `public/loadable-stats.json`
: "loadable-stats.json",
writeToDisk: true
})
]
});
}
};