-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
621 lines (586 loc) Β· 22 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
const { createFilePath } = require("gatsby-source-filesystem");
async function slugifyMarkdownRemarkNode(gatsbyUtils) {
const { actions, node, getNode } = gatsbyUtils;
const { createNodeField } = actions;
if (node.internal.type === "MarkdownRemark") {
const slug = createFilePath({ node, getNode });
createNodeField({
name: "slug",
node,
value: slug,
});
}
}
const { fetchEmbed } = require("./src/services/oembed");
// const YOUTUBE_IDS_RED_STRING = [
// "4nWUMgiEpdc",
// "DaWn3zIpR2Y",
// "sbClENlhHUs",
// "UZImOvL9Q_g",
// "PkmxdC4-lII",
// "8akVGSk4FhQ",
// "zRUxnx7pv0E",
// "ix_0vrwQnWk",
// "dlRbFtih2X0",
// "dtltxhgjLb4",
// ];
// // 2. Loop over each one
// // for (const idPinky of YOUTUBE_IDS_RED_STRING) {
// // create a node for each video
// // }
// // gatsby-node.js
// // G. Get
// // exports.sourceNodes = async ({
// // actions: { createNode },
// // createContentDigest,
// // reporter
// // }) => {
// // // L. Loop over YOUTUBE_IDS_RED_STRING
// // for (const idPinkyPinksbyPirateParrot of YOUTUBE_IDS_RED_STRING) {
// // const embedData = await fetchEmbed(idPinkyPinksbyPirateParrot, reporter);
// // if (!embedData) return;
// // createNode({
// // // G. Get data
// // ...embedData,
// // // I. id
// // id: idPinkyPinksbyPirateParrot,
// // // G. contentDiGest
// // internal: {
// // type: "youTubeEmbed",
// // contentDigest: createContentDigest(idPinkyPinksbyPirateParrot)
// // }
// // });
// // }
// // };
// // Troya Goatsby and Lilly Owlsby are
// // Baking pages with
// // Cap'n Granny Sharksby's
// // createPages hook
// async function bakeMarkdownIntoGoodies({ graphql, actions }) {
// // console.log('Captain Granny Sharksbys createPages hook π');
// // 1. bakingSong = Lilly Owslby sings π¦
// // the bakingSong by Cap'n Granny Sharksby
// const bakingSong = require.resolve("./src/templates/RecipeMarkdown.js");
// // Look for _ _ _ in http://localhost:8000/topping/Duct-Tape π»
// // 2. supplies: data from Markdown files π² in and _ _ _ drawn
// const { data } = await graphql(`
// {
// supplies: allMarkdownRemark(
// sort: { order: ASC, fields: frontmatter___title }
// ) {
// nodes {
// id
// strawberry: frontmatter {
// path
// title
// }
// }
// }
// }
// `);
// // 3. Loop over the markdown nodes and
// // for each bake a page
// data.supplies.nodes.forEach((ahoyGoodie, index) => {
// // console.log('Defer index:', index, ahoyGoodie);
// // A. β B. β C. β DSG π©
// actions.createPage({
// // A. Β«Ahoy! Goodie?!Β»
// // Cap'n Fox shouts and embarks. π¦
// path: `${ahoyGoodie.strawberry.path}`,
// // B. Owlsby sings badly
// // and bakes baby sharks. π¦
// component: bakingSong,
// // C. Catsby looks tasty
// // Fox gets hungry for kitten. π―
// context: {
// catsby: ahoyGoodie.id,
// fox: "Catsby looks tasty I getz hungry for kitten",
// },
// // D. Don't Show Goodies to Fox
// // and maybe get bitten. DSGβπ©
// // catsby build and look for _ _ _ in terminal π
// defer: index + 1 > 2,
// // D. Data tree π€π²
// // E. Every node you must sort π°
// // F. Fields Forever `fields: ,` π
// // E. forEach index
// // R. RRR! defer: index + 1 > 2 π©
// // How does Catsby help Lilly make an index of all the toppings?
// // What is the way Lilly makes index travel from
// // D. Data tree π€π²
// // R. RRR! defer: index + 1 > 2 π©
// });
// });
// }
// // We don't use this yet
// // Captain Granny Sharksby createPages hook β©οΈ
// async function turnTagzIntoPages({ graphql, actions }) {
// // console.log('createPages hook from Captain Sharksby β©οΈ π');
// // 1. bakingSong = Lilly the Bunny require the bakingSong from granny Shark's gingerbread Recipe
// const bakingSong = require.resolve("./src/pages/pizzaTags.js");
// // Look for _ _ _ in http://localhost:8000/tag/eminem π»
// // 2. supplies: tags in markdown files
// const { data } = await graphql(`
// {
// postsRemark: allMarkdownRemark(
// sort: { order: DESC, fields: frontmatter___date }
// limit: 10
// ) {
// edges {
// node {
// frontmatter {
// url
// tags
// }
// }
// }
// }
// tagsGroup: allMarkdownRemark(limit: 20) {
// group(field: frontmatter___tags) {
// totalCount
// fieldValue
// }
// }
// }
// `);
// // 3. turn toppings into pages with
// // createPage method from Captain Sharksby
// data.tagsGroup.group.forEach((ahoyGoodie, index) => {
// // console.log('Defer index:', ahoyGoodie);
// actions.createPage({
// // A. Β«Ahoy! Cookie?!Β»
// // Cap'n Fox shouts and embarks. π¦
// path: `/tag/${ahoyGoodie.fieldValue}`,
// // B. Bunny sings badly
// // and bakes baby sharks. π°
// component: bakingSong,
// // C. Catsby looks tasty
// // Fox gets hungry for kitten. π―
// // context: {
// // catsby: ahoyGoodie.toppings.tags ,
// // //toppingRegex: `/${ahoyCookie}/`,
// // // TODO Regex for Topping
// // // toppingRegex: `/${ahoyCookie.frontmatter.tags}/i`,
// // },
// defer: index + 1 > 2,
// });
// });
// // 5. Pass tag data to pizzaTags.js
// }
// // Troya Catsby and Lilly Owlsby Baking pages
// // with Cap'n Granny Sharksby's
// // createPages hook
// async function turnToolsIntoPages({ graphql, actions }) {
// // 1. bakingSong = Lilly the Owlsby sings like a π¦’
// // console.log('Captain Granny Sharksbys createPages hook');
// const bakingSong = require.resolve("./src/pages/pizzas.js");
// // 2. supplies: toppings data π² in Sanity and _ _ _ drawn
// // Look for _ _ _ in http://localhost:8000/topping/Duct-Tape π»
// const { data } = await graphql(`
// {
// supplies: allSanityTopping(sort: { fields: _createdAt, order: DESC }) {
// nodes {
// name
// id
// }
// }
// }
// `);
// // 3. Loop over the tools nodes and
// // for each create a page with the createPage method
// data.supplies.nodes.forEach((ahoyGoodie, index) => {
// // console.log('Defer index:', index);
// actions.createPage({
// // A. Β«Ahoy Goodie?!Β»
// path: `/tool/${ahoyGoodie.name}`,
// // B. Sing
// component: bakingSong,
// // C. Β«Catsby looks goodie
// // I getz hungry for kitten.Β» // reggae π΅
// context: {
// catsby: ahoyGoodie.name,
// toolRegex: `/${ahoyGoodie.name}/i`,
// },
// // D. Don't Show Goodies to Fox
// // and maybe get bitten. π©
// defer: index + 1 > 14,
// // How does Catsby help Lilly make an index of all the toppings?
// // What is the way Lilly makes index travel from start to defer?
// // D. π€ Data tree in your GraphiQL garden
// // E. π© Every node you sort
// // F. is for Fields, π `fields: ....,`
// // E. is for Each, forEach .... index
// // R. Rrr! defer: index + 1 > 3
// // props.pageContext.defer:
// // props.pageContext.ownerNodeId on Sunday
// ownerNodeId: ahoyGoodie.id,
// });
// });
// // 5. Pass tag data to pizzaTags.js
// }
// async function bakingPhotosIntoPages({ graphql, actions }) {
// const bakingSong = require.resolve("./src/templates/RecipeSong.js");
// const { data } = await graphql(`
// {
// supplies: allSanityPizza(sort: { fields: _createdAt, order: ASC }) {
// nodes {
// name
// id
// slug {
// current
// }
// }
// }
// }
// `);
// // 4. Loop over the toppings and
// // turn them into pages with createPage
// data.supplies.nodes.forEach((ahoyCookie, index) => {
// // console.log('Defer index:', index, ahoyCookie);
// actions.createPage({
// // A. Β«Ahoy Goodie?!Β»
// path: `${ahoyCookie.slug.current}`,
// // B.
// component: bakingSong,
// // C. Catsby looks tasty
// context: {
// // fox: 'Catsby looks tasty, I get hungry for lunch-kitten',
// catsby: ahoyCookie.id,
// // catsby: 'looks tasty', pælme ut den ene, bare ha en nøkkel
// toppingRegex: `/${ahoyCookie.name}/i`, // reggae
// },
// defer: index + 1 > 3,
// // // How does Catsby help Lilly make an index of all the toppings?
// // // What is the way Lilly makes index travel from start to defer?
// // // D. π€ Data tree in your GraphiQL garden
// // // E. π© Every node you sort
// // // F. is for Fields, π `fields: ....,`
// // // E. is for Each, forEach .... index
// // // R. Rrr! defer: index + 1 > 3
// // // props.pageContext.defer:
// // // props.pageContext.ownerNodeId on Sunday
// ownerNodeId: ahoyCookie.id,
// });
// });
// }
// // 1. Baking Pages with Captain Granny Sharksby's hook
// async function bakeImagesIntoGoodies({ graphql, actions }) {
// // console.log('Captain Granny Sharksbys hook');
// // 2. bakingSong = Lilly the Bunny require the bakingSong from granny Shark's gingerbread Recipe, π¦’
// const bakingSong = require.resolve("./src/templates/Recipe.js");
// // 3. bakingSupplies: image files in folders, drawn
// // Look for _ _ _ in http://localhost:8000/uniBeaver-1π»
// const { data } = await graphql(`
// {
// supplies: allFile(
// filter: { sourceInstanceName: { eq: "images" } }
// sort: { fields: name, order: DESC }
// ) {
// nodes {
// name
// id
// }
// }
// }
// `);
// // console.log(data.supplies.nodes.id);
// // 4. Loop over the image nodes and for each create a page
// data.supplies.nodes.forEach((ahoyCookie, index) => {
// // console.log('Defer index:', index);
// // A. π¦
// // B. π°
// // C. π―
// // D. π© DSG
// actions.createPage({
// // A. Β«Ahoy! Cookie?!Β»
// // Cap'n Fox shouts and embarks. π¦
// path: `${ahoyCookie.name}`,
// // B. Bunny sings badly
// // and bakes baby sharks. π°
// // catsby develop Look for _ _ _ in localhostπ»
// component: bakingSong,
// // C. Catsby looks tasty
// // Fox gets hungry for kitten. π―
// // Look for _ _ _ in localhostπ»
// context: {
// catsby: "looks tasty",
// fox: "gets hungry for kitten",
// id: ahoyCookie.id,
// },
// // D. Don't Show Goodies to Fox
// // and maybe get bitten. π©
// // catsby build and look for _ _ _ in terminal π
// defer: index + 1 > 2,
// });
// });
// }
// // 1. Captain Granny Sharksby createPages hook β©οΈ
// async function turnNamesIntoTags({ graphql, actions }) {
// // console.log('Captain Granny Sharksbys hook');
// // 2. bakingTagSong = Lilly the Bunny require the bakingSong from granny Shark's gingerbread Recipe
// const bakingTagSong = require.resolve("./src/pages/image-tags.js");
// // // 3. bakingSupplies: tags in markdown files
// const { data } = await graphql(`
// {
// supplies: allFile(
// filter: { sourceInstanceName: { eq: "images" } }
// sort: { order: ASC, fields: name }
// ) {
// nodes {
// name
// id
// }
// }
// }
// `);
// // console.log(data.supplies.nodes);
// // 4. turn toppings into pages with
// // Cap'n Granny Sharksby's createPages hook
// data.supplies.nodes.forEach((ahoyCookie, index) => {
// // console.log('Defer index:', index, ahoyCookie);
// // A. π¦
// // B. π°
// // C. π―
// // D. π© DSG
// actions.createPage({
// // A. Β«Ahoy! Cookie?!Β»
// // Cap'n Fox shouts and embarks. π¦
// path: `/image-tags/topping/${ahoyCookie.name}`,
// // B. Bunny sings badly
// // and bakes baby sharks. π°
// component: bakingTagSong,
// // C. Catsby looks tasty
// // Fox gets hungry for kitten. π―
// context: {
// id: ahoyCookie.id,
// // topping: ahoyCookie.toppings.tags ,
// //toppingRegex: `/${ahoyCookie}/`,
// // TODO Regex for Topping
// // toppingRegex: `/${ahoyCookie.frontmatter.tags}/i`,
// },
// defer: index + 1 > 2,
// });
// });
// // 5. Pass tag data to pizzaTags.js
// }
// // G.
// // i.
// // G.
// // G.
// // Get data and gut gulls π¦
// // go res fetch! Emπ
// // u return data
// // try
// // get πͺ.get("πΊπ/oembed",
// // url: `https://youtu.π/${π¦}`,
// // logger.info(`πͺ`);
// // logger.warn(`πͺ`);
// // s async
// // L. Loop over
// // E.
// // S.
// // const axios = require("axios");
// // const OLA_TUBE_ID = "4nWUMgiEpdc"
// // const OLA_CAST_IDS_RED_STRING = ["4nWUMgiEpdc", "DaWn3zIpR2Y", "sbClENlhHUs", "UZImOvL9Q_g", "PkmxdC4-lII", "8akVGSk4FhQ", "zRUxnx7pv0E", "ix_0vrwQnWk", "dlRbFtih2X0", "dtltxhgjLb4"];
// // async function getVideosAndBakeNodes({
// // actions, createContentDigest
// // }) {
// // console.log(' πΊ π get videos and bake nodes π°');
// // OLA_CAST_IDS_RED_STRING.forEach(OLA_TUBE_ID => {
// // for (const OLA_TUBE_ID of OLA_CAST_IDS_RED_STRING) {
// // G.
// // const oembedVideo = await axios.get("https://www.youtube.com/oembed",
// // {params: {
// // url: `https://youtu.be/${OLA_TUBE_ID}`,
// // maxwidth: 800
// // }}
// // );
// // console.log(oembedVideo);
// // if (!oembedVideo) return;
// // // I.
// // actions.createNode({
// // id: OLA_TUBE_ID,
// // ...oembedVideo,
// // internal: {
// // contentDigest: createContentDigest(OLA_TUBE_ID),
// // type: "olaTubeOemBed"
// // }
// // });
// // };
// // };
// // G. Get data later
// // I. id in between
// // a. actions
// // c. contentDigest
// // t. type
// // i. internal: {
// // o. (OLA_TUBE_ID)
// // n. node
// // s. Sing
// // G. Gut
// // G. Gulls π¦ to get oembed data
// // L. Loop over nodes
// // E. Embed one video per page
// // S. Sing $id: String
// // const oembedVideo = await axios.get("https://www.youtube.com/oembed",
// // {params: {
// // url: `https://youtu.be/${OLA_TUBE_ID}`,
// // maxwidth: 1554
// // }}
// // );
// // console.log(oembedVideo);
// // if (!oembedVideo) return;
const axios = require("axios");
const { graphql } = require("gatsby");
const POW_PUG_TUBE_IDS = ["UGq8cnNTbwI", "eRTJPIa39a4"];
// added 15 and 16
const POW_TUBE_IDS_RED_STRING = [
"4nWUMgiEpdc",
"DaWn3zIpR2Y",
"sbClENlhHUs",
"UZImOvL9Q_g",
"PkmxdC4-lII",
"8akVGSk4FhQ",
"zRUxnx7pv0E",
"ix_0vrwQnWk",
"dlRbFtih2X0",
"dtltxhgjLb4",
"LQ2DRJbG8FY",
"rPiQi_bOk8s",
];
async function bakeOneNodeGetOneVideo({ actions, createContentDigest }) {
// George β
// G. Gus gets oembedVideo from Axios River, await
// U. url: `https://youtu.π/${π¦}`, but first https://www.youtube.com/oembed
// S. Spread 8:25 -> 9:00
for (pinkyPinksbyPiratyParrot of POW_TUBE_IDS_RED_STRING) {
const oembedVideo = await axios.get("https://www.youtube.com/oembed", {
params: {
url: `https://youtu.be/${pinkyPinksbyPiratyParrot}`,
maxwidth: 1554,
},
});
actions.createNode({
id: pinkyPinksbyPiratyParrot,
...oembedVideo,
//gus: oembedVideo,
internal: {
contentDigest: createContentDigest(pinkyPinksbyPiratyParrot),
type: "olaTubeOemBed",
},
});
}
}
// async function bakeMarkdownIntoGingerbreadHouse({ graphql, actions }) {
// console.log("π bakeMarkdownIntoGingerbreadHouse π");
// // 1. supplies! from Data River
// const { data } = await graphql(`
// {
// supplies: allMarkdownRemark {
// nodes {
// id
// }
// }
// }
// `);
// console.log("ππ", data.supplies.nodes);
// // 2. bakingSong
// const bakingSong = require.resolve("./src/templates/bakingSong.js");
// // 3. Loop over the nodes and for each create a page
// data.supplies.nodes.forEach((ahoyGingerSection) => {
// console.log("πππ", ahoyGingerSection.id);
// actions.createPage({
// // A. Ahoy! Baking aroma!
// path: ahoyGingerSection.id,
// // B. bakingSong
// component: bakingSong,
// // C. catsby
// context: {
// catsby: ahoyGingerSection.id,
// },
// });
// });
// }
// POW!-website/gatsby-node.js
// I will delete all these comments and rename everything after my
// livestream on Thursday Feb 24.
// badly baked GingerBreadPages π
// Only bake pages for markdown pages π and not sections. γοΈ π
// 0. Only index.md π
async function bakeMarkdownNodesIntoPages({ graphql, actions }) {
// 1. filter β
// supplies: not allMarkdownRemark.nodes π°
const { data } = await graphql(`
{
supplies: allMarkdownRemark(
filter: { fileAbsolutePath: { regex: "/index.md/" } }
) {
nodes {
id
fields {
slug
}
}
}
}
`);
console.log(data.supplies.nodes);
// 2. bakingsong π΅ π
const bakingSong = require.resolve("./src/templates/pageTemplate.js");
// 3. aromaNode π°
// Loop over the supplies.nodes and forEach((aromaNode and bake a page
data.supplies.nodes.forEach((aromaNode) => {
console.log(aromaNode.fields.slug, "ππ");
const aromaNodePath =
aromaNode.fields.slug === "/index/" ? "/" : aromaNode.fields.slug;
actions.createPage({
// A. aromaNodePath π°.π.π
path: aromaNodePath,
// B. bakingSong π΅ π
component: bakingSong,
// C. catsbyId πΌπ
context: {
catsbyId: aromaNode.id,
},
});
});
}
exports.onCreateNode = async (gatsbyUtils) => {
await Promise.all([slugifyMarkdownRemarkNode(gatsbyUtils)]);
};
exports.sourceNodes = async (params) => {
// Bake one node and source it into our GraphQL-Gatsby data-river
await Promise.all([bakeOneNodeGetOneVideo(params)]);
};
// 0. export Baking Pages with Captain Granny Sharksby's createPages hook β©οΈ
exports.createPages = async (gatsbyUtils) => {
// create pages dynamically from any data source like for example see below:
// wait for all promises to be resolved before finishing this function
await Promise.all([
// bakeMarkdownIntoGoodies(gatsbyUtils),
// turnTagzIntoPages(gatsbyUtils),
// bakeMarkdownIntoGingerbreadHouse(gatsbyUtils),
// turnToolsIntoPages(gatsbyUtils),
// bakingPhotosIntoPages(gatsbyUtils),
// bakeImagesIntoGoodies(gatsbyUtils),
// turnNamesIntoTags(gatsbyUtils),
bakeMarkdownNodesIntoPages(gatsbyUtils),
]);
// markdown in local files
// RecipeMarkdown.js
// pizzaTags.js Don't hook up markdown and tags yet
// sanity.io
// pizzas.js is tools
// RecipeSong.js is photos
// images in local files
// Recipe.js
// image-tags.js
// POW!-style markdown
};
// 1.2.3 β A.B.C. β Gingerbread house
// 1. Supplies: allMarkdownRemark.node
// 2. Bakingsong = bakingSong.js
// 3. Loop over the supply node and create a page
// A. Ahoy! Aroma path!
// B. BakingSong is a component
// C. Catsby node.id is context