-
Notifications
You must be signed in to change notification settings - Fork 44
/
gatsby-node.js
215 lines (194 loc) · 4.98 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
const path = require('path')
const { paginate } = require('gatsby-awesome-pagination')
const { createFilePath } = require(`gatsby-source-filesystem`)
exports.createPages = async ({ actions, graphql }) => {
const { createPage } = actions
const query = await graphql(`
{
site {
siteMetadata {
postsPerPage
}
}
posts: allMdx(
sort: { order: DESC, fields: frontmatter___date }
filter: {
fileAbsolutePath: { regex: "/gatherings/" }
frontmatter: { youtube_playlist_id: { regex: "/.*/" } }
}
) {
nodes {
slug
}
}
}
`)
// Check for any errors
if (query.errors) {
throw new Error(query.errors)
}
const posts = query.data.posts.nodes
const gatheringIndexTemplate = path.resolve(`src/templates/gatherings.js`)
// Create your paginated pages
paginate({
createPage, // The Gatsby `createPage` function
items: posts, // An array of objects
itemsPerPage: query.data.site.siteMetadata.postsPerPage,
pathPrefix: '/gatherings', // Creates pages like `/gatherings`, `/gatherings/2`, etc
component: gatheringIndexTemplate,
})
}
exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions
if (node.internal.type === `Mdx`) {
const value = createFilePath({ node, getNode })
createNodeField({
name: `slug`,
node,
value,
})
}
}
// Define schema for frontmatter
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
const typeDefs = `
type MdxFrontmatter {
title: String!
description: String
menu: String
language: String
date(
formatString: String
fromNow: Boolean
difference: String
locale: String
): Date
timezone: String
start_time: String
end_time: String
location: String
venue: String
venue_URL: String
venue_address: String
google_maps_URL: String
registration_text: String
registration_URL: String
registration_text2: String
registration_URL2: String
registration_text3: String
registration_URL3: String
price: String
sponsoring_URL: String
sponsoring_text: String
sponsors: [MdxFrontmatterSponsors]
head_text: String
lead_text: String
info_text: String
event_footer_text: String
invite_link: String
hidefromsearch: Boolean
invite_a_friend: String
schedule_leadin: String
videos_text: String
translate_overview: String
translate_schedule: String
translate_speakers: String
translate_venue: String
translate_where: String
translate_when: String
translate_price: String
translate_invite: String
translate_sponsors: String
link: String
link_text: String
prev_link: String
image: File
alt: String
videos: [MdxFrontmatterVideos]
}
type MdxFrontmatterSponsors {
name: String
label: String
level: Int
link: String
}
type MdxFrontmatterVideos {
gathering_title: String
gathering_date(
formatString: String
fromNow: Boolean
difference: String
locale: String
): Date
gathering_videos: [MdxFrontmatterVideosGathering_videos]
}
type MdxFrontmatterVideosGathering_videos {
publishedAt(
formatString: String
fromNow: Boolean
difference: String
locale: String
): Date
channelId: String
title: String
description: String
thumbnails: MdxFrontmatterVideosGathering_videosThumbnails
channelTitle: String
playlistId: String
position: Int
resourceId: MdxFrontmatterVideosGathering_videosResourceId
videoOwnerChannelTitle: String
videoOwnerChannelId: String
}
type MdxFrontmatterVideosGathering_videosThumbnails {
default: MdxFrontmatterVideosGathering_videosThumbnailsDefault
medium: MdxFrontmatterVideosGathering_videosThumbnailsMedium
high: MdxFrontmatterVideosGathering_videosThumbnailsHigh
standard: MdxFrontmatterVideosGathering_videosThumbnailsStandard
maxres: MdxFrontmatterVideosGathering_videosThumbnailsMaxres
}
type MdxFrontmatterVideosGathering_videosThumbnailsDefault {
url: String
width: Int
height: Int
}
type MdxFrontmatterVideosGathering_videosThumbnailsMedium {
url: String
width: Int
height: Int
}
type MdxFrontmatterVideosGathering_videosThumbnailsHigh {
url: String
width: Int
height: Int
}
type MdxFrontmatterVideosGathering_videosThumbnailsStandard {
url: String
width: Int
height: Int
}
type MdxFrontmatterVideosGathering_videosThumbnailsMaxres {
url: String
width: Int
height: Int
}
type MdxFrontmatterVideosGathering_videosResourceId {
kind: String
videoId: String
}
type SpeakersYaml implements Node {
id: ID!
parent: Node
children: [Node!]!
internal: Internal!
speaker_id: String
name: String
role: String
company: String
url: String
intro: String
}
`
createTypes(typeDefs)
}