-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgatsby-node.js
45 lines (42 loc) · 1.2 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
const fs = require("fs");
const metadata = require("./metadata.json");
// const fetch = require("node-fetch");
const getSpacebudz = () => {
return Object.keys(metadata).map((id) => {
const price =
Math.random() > 0.5 ? Math.floor(Math.random() * 100) + 1 : null;
const type = metadata[id].type;
const gadgets = metadata[id].traits;
return {
id,
// price,
type,
gadgets,
};
});
};
const shuffle = (array) => {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
};
exports.createPages = async ({ actions: { createPage } }) => {
// `getPokemonData` is a function that fetches our data
const spacebudz = getSpacebudz();
// shuffle(spacebudz);
// Create a page that lists all Pokémon.
createPage({
path: `/explore/`,
component: require.resolve("./src/templates/explore.js"),
context: { spacebudz },
});
// Create a page for each Pokémon.
spacebudz.forEach((spacebud) => {
createPage({
path: `/explore/spacebud/${spacebud.id}/`,
component: require.resolve("./src/templates/spacebud.js"),
context: { spacebud },
});
});
};