-
Notifications
You must be signed in to change notification settings - Fork 2
/
gatsby-node.js
141 lines (132 loc) · 4.25 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
const { createFilePath } = require(`gatsby-source-filesystem`)
exports.createPages = async function ({ actions, graphql }) {
const { data } = await graphql(`
query {
dataJson {
composers {
name
full_name
birth
death
wikipedia
extra_link
extra_link_title
}
greats {
composer
catalog
completed
imslp
key
notes
opus_imslp
opus_nickname
opus_notes
title
wikipedia
work_nickname
work_number
}
movements {
catalog
composer
grouping
key
movement_number
spotify
title
work_number
notes
}
}
}
`)
// add a count of quartets by each composer to their entry. Don't hard code work counts
// because e.g. schubert and mendelssohn could get more quartets added ...
let counts = {
'Bach': 0,
'Bartok': 0,
'Beethoven': 0,
'Boccherini': 0,
'Brahms': 0,
'Britten': 0,
'Debussy': 0,
'Dvorak': 0,
'Grieg': 0,
'Haydn': 0,
'Mendelssohn': 0,
'Mozart': 0,
'Prokofiev': 0,
'Ravel': 0,
'Schubert': 0,
'Schumann': 0,
'Shostakovich': 0,
'Tchaikovsky': 0,
}
data.dataJson.greats.forEach(node => {
counts[node.composer] += 1;
});
data.dataJson.composers.forEach(node => node.quartets = counts[node.name]);
// console.log(JSON.stringify(data.dataJson, null, 4))
// console.log(JSON.stringify(data.dataJson, null, 4))
// https://jonsully.net/blog/trailing-slashes-and-gatsby/
data.dataJson.composers.forEach(node => {
// console.log(node);
actions.createPage({
path: node.name + '/',
component: require.resolve(`./src/templates/composer.js`),
context: { node: node, data: data.dataJson.greats },
})
})
let slugify = function(node){
let catalog = n => n.catalog.toLowerCase().split(" ").join("-") + (n.work_number ? '-' + n.work_number : '');
let number = n => n.title;
let singular = n => 'quartet';
let mozart = n => "k-" + n.catalog.replace("K", ""); // K387 -> k-387
let boccherini = n => n.catalog.toLowerCase();
// each composer's quartes are commonly identified a bit differently.
// let the slug reflect that.
let idf = {
'Bach': catalog,
'Bartok': number,
'Beethoven': catalog,
'Boccherini': boccherini,
'Brahms': catalog,
'Britten': number,
'Debussy': singular,
'Dvorak': catalog,
'Grieg': singular,
'Haydn': catalog,
'Mendelssohn': catalog,
'Mozart': mozart,
'Prokofiev': number,
'Ravel': singular,
'Schubert': catalog,
'Schumann': number,
'Shostakovich': number,
'Tchaikovsky': number,
}
return '/' + node.composer.toLowerCase() +
'-' + idf[node.composer](node) + '/';
}
data.dataJson.greats.forEach(node => {
// console.log(JSON.stringify(node));
// console.log(slugify(node));
const slug = slugify(node);
actions.createPage({
path: slug,
component: require.resolve(`./src/templates/work.js`),
context: { node: node, data: data.dataJson },
})
})
actions.createPage({
path: "/random",
component: require.resolve(`./src/templates/random.js`),
context: { node: data.dataJson },
})
actions.createPage({
path: "/random-composer",
component: require.resolve(`./src/templates/random-composer.js`),
context: { node: data.dataJson },
})
}