-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgatsby-node.js
78 lines (73 loc) · 1.59 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
const { DateTime, Duration } = require("luxon")
const path = require(`path`)
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
const typeDefs = `
type StreamsJson implements Node @dontInfer {
name: String!
color: String!
twitch_handle: String
youtube_url: String
schedule: [Stream!]
}
type Stream {
title: String!
description: String
start_time: Date!
start_time_ms: Int
duration_in_minutes: Int
stream_links: [StreamLink!]
}
type StreamLink {
platform: String!
url: String
}
`
createTypes(typeDefs)
}
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
const firstMonth = DateTime.now()
.toUTC()
.minus(Duration.fromObject({ weeks: 4 }))
.startOf("month")
const indexTemplate = path.resolve(`./src/templates/index.tsx`)
return graphql(`
{
streamers: allStreamsJson {
nodes {
twitch_handle
name
schedule {
description
duration_in_minutes
title
stream_links {
platform
url
}
start_time
}
youtube_url
color
}
}
}
`).then(({ data }) => {
// filter data here (i.e. at build-time) to prevent shipping outdated stream schedules
// to website visitors
const streamers = data.streamers.nodes
.map(streamer => ({
...streamer,
schedule: streamer.schedule.filter(
stream => DateTime.fromISO(stream.start_time) > firstMonth
),
}))
.filter(streamer => streamer.schedule.length > 0)
createPage({
path: `/`,
component: indexTemplate,
context: { streamers },
})
})
}