-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
92 lines (83 loc) · 2.6 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
const path = require("path")
// docs: https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#createPages
// using the file system route api may be easier than using the createPage API?
// https://www.gatsbyjs.com/docs/reference/routing/file-system-route-api/
exports.onCreateNode = ({ node, getNode }) => {
// console.log(`Node created of type "${node.internal.type}"`)
// if (node.internal.type === 'ComposersCsv'){
// one node per composer, not ideal
if (node.internal.type === 'PlaylistsJson'){
// console.log(node.date);
}
}
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
// graphql returns a Promise
const cresult = await graphql(`
query {
allComposersCsv {
group(field: birthday) {
totalCount
fieldValue
field
nodes {
name
birthdate
birthday
birthyear
deathdate
deathday
deathyear
genres
sp_followers
sp_id
sp_img_url
sp_popularity
sp_url
wd_url
wp_url
wp_views
}
}
}
}`)
// console.log(JSON.stringify(result, null, 4));
const presult = await graphql(`
query {
allPlaylistsJson {
nodes {
date
draft
status
sampler
long
other
}
}
}
`)
console.log(JSON.stringify(presult.data.allPlaylistsJson.nodes[0], null, 4))
let playlists = {};
presult.data.allPlaylistsJson.nodes.forEach( n => {
playlists[n.date] = n;
});
cresult.data.allComposersCsv.group.forEach( group => {
// "April 02" -> 04/11
let d = new Date(Date.parse(group.fieldValue));
// TODO: one day pull this from src/lib/utils.js
let slug = "/" + (d.getMonth() + 1) + "-" + d.getDate();
let ds = (d.getMonth() + 1) + "/" + d.getDate();
console.log("path: ", slug, "Count: ", group.totalCount);
// console.log(d, ds);
let template = path.resolve("./src/templates/day.js");
createPage({
path: slug,
component: template,
context: {
date_str: group.fieldValue,
playlist: playlists[ds],
group: group,
},
})
})
}