-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
65 lines (61 loc) · 1.57 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
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const path = require(`path`);
const slugify = require(`slugify`);
exports.modifyWebpackConfig = ({ config, stage }) => {
// Fix for D3
config.merge({
node: { fs: 'empty', child_process: 'empty', pym: 'empty' },
module: { noParse: /(mapbox-gl)\.js$/ },
})
if (stage === "build-html") {
config.loader("null", {
test: /(mapbox-gl)\.js$/,
loader: "null-loader",
});
}
return config
}
exports.onCreatePage = async ({ page, boundActionCreators }) => {
const { createPage } = boundActionCreators;
return new Promise((resolve, reject) => {
if (page.path == "/embed/") {
page.layout = "embedPreview";
createPage(page);
}
resolve();
});
};
exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators
return new Promise((resolve, reject) => {
graphql(`
{
allMxstatesJson {
edges {
node {
state_name
state_code
}
}
}
}
`).then(result => {
result.data.allMxstatesJson.edges.map(({ node }) => {
var slug = slugify(node.state_name, {lower: true})
createPage({
path: slug + '/',
component: path.resolve(`./src/templates/map.js`),
context: {
// Data passed to context available in page queries as GraphQL variables.
state_code: node.state_code,
},
})
})
resolve()
})
})
}