-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
90 lines (80 loc) · 2.11 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
const path = require("path")
exports.createPages = async ({ actions, graphql }) => {
const { createPage } = actions
const result = await graphql(`
query {
pokeapi {
allPokemon(limit: 151) {
id
name
dominant_color {
original
light
dark
}
nat_dex_num
}
}
}
`)
createPage({
path: "/",
component: path.resolve(`./src/templates/home.js`),
context: {
allPokemon: result.data.pokeapi.allPokemon,
},
})
createPage({
path: "/pokemon",
component: path.resolve(`./src/templates/home.js`),
context: {
allPokemon: result.data.pokeapi.allPokemon,
},
})
// create individual pokemon pages
result.data.pokeapi.allPokemon.forEach(pokemon => {
const slug = `pokemon/${pokemon.name}`
// want to exclude alternate forms for the home page
const prevId = pokemon.id - 1 > 0 ? pokemon.id - 1 : 893 // Zarude is the last pokemon w/ id of 893
const nextId = pokemon.id + 1 <= 893 ? pokemon.id + 1 : 1
createPage({
path: slug,
component: path.resolve(`./src/templates/pokemon.js`),
context: {
id: pokemon.id,
name: pokemon.name,
dominant_color: pokemon.dominant_color,
prevPokemonId: prevId,
nextPokemonId: nextId,
allPokemon: result.data.pokeapi.allPokemon,
},
})
createPage({
path: `${slug}/stats`,
component: path.resolve(`./src/templates/stats.js`),
context: {
id: pokemon.id,
name: pokemon.name,
dominant_color: pokemon.dominant_color,
},
})
createPage({
path: `${slug}/evolution`,
component: path.resolve(`./src/templates/evolution.js`),
context: {
id: pokemon.id,
name: pokemon.name,
dominant_color: pokemon.dominant_color,
},
})
createPage({
path: `${slug}/moves`,
component: path.resolve(`./src/templates/moves.js`),
context: {
id: pokemon.id,
name: pokemon.name,
dominant_color: pokemon.dominant_color,
},
})
})
}