-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
34 lines (33 loc) 路 755 Bytes
/
Copy pathgatsby-node.js
File metadata and controls
34 lines (33 loc) 路 755 Bytes
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
const path = require('path');
exports.createPages = ({ actions, graphql }) => {
const { createPage } = actions;
const postTemplate = path.resolve('src/templates/post.js');
return new Promise((resolve, reject) => {
graphql(`
query queryTitle {
allDataJson {
edges {
node {
id
slug
}
}
}
}
`).then(res => {
if(res.errors) {
return Promise.reject(res.errors);
}
res.data.allDataJson.edges.forEach(({ node }) => {
createPage({
path: `/${node.id}/`,
component: postTemplate,
context: {
id: `${node.id}`
}
})
resolve();
})
})
});
}