-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gatsby-node.js
75 lines (71 loc) · 2.47 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
const path = require('path');
const GalleryPageTemplate = path.resolve('./src/components/GalleryPage/GalleryPageTemplate.js');
function getHothWinners(allHothWinners) {
const hothWinners = new Map();
const devposts = new Map();
const allHothNames = new Map();
const allGalleryLinks = new Map();
for (const hoth of allHothWinners) {
const winnersArray = [];
for (const winner of hoth.parent.childYaml.winners) {
const { category, description, image, link, title } = winner;
const winnerCopy = { category, description, image, link, title };
winnersArray.push(winnerCopy);
}
hothWinners.set(hoth.parent.name, winnersArray);
devposts.set(hoth.parent.name, hoth.parent.childYaml.devpost);
allHothNames.set(hoth.parent.name, hoth.parent.childYaml.name);
allGalleryLinks.set(hoth.parent.name, `/gallery/${hoth.parent.name}`);
}
return { hothWinners, devposts, allHothNames, allGalleryLinks };
}
exports.createPages = async ({ actions: { createPage }, graphql }) => {
const hothData = await graphql(`
query HothDataQuery {
allYaml(sort: {fields: name, order: DESC}) {
nodes {
parent {
... on File {
id
name
childYaml {
name
devpost
winners {
category
description
image
link
title
}
}
}
}
}
}
}
`);
const { hothWinners, devposts, allHothNames, allGalleryLinks } = getHothWinners(hothData.data.allYaml.nodes);
const hothNames = Array.from(allHothNames.values());
const galleryLinks = Array.from(allGalleryLinks.values());
for (const key of hothWinners.keys()) {
const hothName = allHothNames.get(key);
const winnerInfo = hothWinners.get(key);
const devpostLink = devposts.get(key);
const galleryLink = allGalleryLinks.get(key);
// This is an absurd number of props and there is probably a much
// better way to do this that somebody can figure out at a later time
// On the bright side it is now easier to change names and links
createPage({
path: `${galleryLink}`,
component: GalleryPageTemplate,
context: {
winnerInfo,
devpostLink,
hothNames, // all HOTH names for GalleryMenu
galleryLinks, // all links for GalleryMenu
hothName // name of current HOTH for Winners
}
});
}
};