-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgatsby-node.js
38 lines (35 loc) · 867 Bytes
/
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
const path = require('path');
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
// eslint-disable-next-line
const createBlogsPosts = new Promise((resolve, reject) => {
try {
graphql(`
{
allDatoCmsBlogPost {
nodes {
slug
}
}
}
`).then(res => {
const posts = res.data.allDatoCmsBlogPost.nodes;
posts.map(post => {
const { slug } = post;
createPage({
path: `/blog/${slug}`,
component: path.resolve('./src/templates/BlogPost.js'),
context: {
slug,
},
});
});
resolve();
});
} catch (error) {
reject(error);
}
});
// eslint-disable-next-line
return Promise.all([createBlogsPosts]);
};