-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
49 lines (44 loc) · 1.36 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
"use strict"
const path = require(`path`);
// Implement the Gatsby API “createPages”. This is called once the
// data layer is bootstrapped to let plugins create pages from data.
exports.createPages = ({ actions, graphql }) => {
// need createRedirect action in actions collection
// to make the redirection magic happen.
// https://www.gatsbyjs.org/docs/bound-action-creators/
const { createRedirect } = actions
// Let’s set up some string consts to use thoroughout the following.
// MDN > JavaScript reference > Statements and declarations
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
// Maybe we usually redirect to page 2, with trailing slash.
const rootPath = '/'
const { createPage } = actions;
return new Promise((resolve, reject) => {
graphql(`
{
allTransmitterListing20110702Json {
edges {
node {
id
}
}
}
}
`
).then(result => {
result.data.allTransmitterListing20110702Json.edges.forEach(({ node }) => {
createPage({
path: `transmitters/${node.id}/`,
component: path.resolve(`./src/templates/Transmitter/index.jsx`),
context: {
transmitterID: node.id
},
})
})
resolve()
})
}).catch(error => {
console.log(error)
reject()
})
}