-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgatsby-node.js
More file actions
executable file
·53 lines (50 loc) · 1.24 KB
/
Copy pathgatsby-node.js
File metadata and controls
executable file
·53 lines (50 loc) · 1.24 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
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const path = require(`path`);
exports.onCreateNode = ({ node, boundActionCreators }) => {
const { createNodeField } = boundActionCreators;
if (node.internal.type === `PrismicDocument`) {
if (node.type == 'page') {
const slug = '/' + node.uid;
createNodeField({
node,
name: `slug`,
value: slug,
});
}
}
};
exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators;
return new Promise((resolve, reject) => {
graphql(`
{
allPrismicDocument(filter: { type: { eq: "page" } }) {
edges {
node {
fields {
slug
}
}
}
}
}
`
).then(result => {
result.data.allPrismicDocument.edges.forEach(({ node }) => {
createPage({
path: node.fields.slug,
component: path.resolve(`./src/templates/page.js`),
context: {
// Data passed to context is available in page queries as GraphQL variables.
slug: node.fields.slug,
},
})
})
resolve();
})
})
};