-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
68 lines (65 loc) · 1.78 KB
/
gatsby-node.js
File metadata and controls
68 lines (65 loc) · 1.78 KB
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
/**
* See: https://www.gatsbyjs.org/docs/node-apis/
called whenever new node is created/updated
*/
const { createFilePath } = require(`gatsby-source-filesystem`)
const path = require(`path`)
exports.onCreateWebpackConfig = ({ stage, rules, loaders, actions }) => {
switch (stage) {
case 'build-html':
actions.setWebpackConfig({
module: {
rules: [
{
test: /react-leaflet/,
use: [loaders.null()]
}
]
}
});
break;
}
};
exports.onCreateNode = ({ node, getNode, actions }) => {
// createNodeField allows additional fields on nodes created by other apis
const { createNodeField } = actions
if(node.internal.type === `ImageSharp`) {
// getNode traverses 'node graph' to get to parent File node
const slug = createFilePath({ node, getNode, basePath: `images` })
createNodeField({
node,
name: `slug`,
value: slug,
})
}
}
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions
// **Note:** The graphql function call returns a Promise
// see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise for more info
return graphql(`
{
allImageSharp(filter: { fields: { slug: { regex: "/barn/" }} }) {
edges {
node {
fields {
slug
}
}
}
}
}
`).then(result => {
result.data.allImageSharp.edges.forEach(({ node }) => {
createPage({
path: node.fields.slug,
component: path.resolve(`./src/templates/barn.js`),
context: {
// Data passed to context is available
// in page queries as GraphQL variables.
slug: node.fields.slug,
},
})
})
})
}