-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.js
105 lines (98 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const path = require('path')
exports.onCreateWebpackConfig = ({ stage, actions, loaders }) => {
if (stage === "build-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /mapbox-gl/,
use: loaders.null()
},
],
}
})
}
actions.setWebpackConfig({
resolve: {
modules: [path.resolve(__dirname, "src"), "node_modules"]
},
module: {
rules: [
{
test: /\.worker.js$/i,
exclude: /node_modules/,
use: [
'worker-loader'
]
}
]
},
output: {
libraryTarget: "this"
}
})
}
// Implement the Gatsby API “createPages”. This is called once the
// data layer is bootstrapped to let plugins create pages from data.
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
return new Promise((resolve, reject) => {
const SchoolTemplate = path.resolve(`src/templates/School.js`)
// Query for markdown nodes to use in creating pages.
resolve(
graphql(
`
{
allSchool {
edges {
node {
id,
media,
meta{
regon
}
}
}
}
}
`
).then(result => {
if (result.errors) {
reject(result.errors)
}
// Create pages for each markdown file.
result.data.allSchool.edges.forEach(({ node }) => {
console.log(node)
createPage({
path: `school/${node.meta.regon}`,
component: SchoolTemplate,
// In your blog post template's graphql query, you can use path
// as a GraphQL variable to query for data from the markdown file.
context: {
id: node.id,
},
})
})
})
)
})
}
exports.onCreatePage = ({ page, actions }) => {
const { createPage, createRedirect } = actions
// createRedirect({
// fromPath: `/school`,
// isPermanent: true,
// redirectInBrowser: true,
// toPath: '/search',
// })
//
// if (page.path.startsWith('/school/')) {
// page.matchPath = `${page.path}/*`
// createPage(page)
// }
}