-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
57 lines (52 loc) · 1.23 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
/*jshint esversion: 6 */
const Promise = require("bluebird");
const path = require("path");
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions;
const additionalPage = require.resolve("./src/templates/additional-page.js");
const newsComponent = require.resolve("./src/templates/news-post.js");
return graphql(
`
{
allContentfulAdditionalPage {
edges {
node {
slug
}
}
}
allContentfulNews {
edges {
node {
slug
}
}
}
}
`
).then((result) => {
if (result.errors) {
console.log(result.errors);
}
const posts = result.data.allContentfulAdditionalPage.edges;
posts.forEach((post) => {
createPage({
path: `/page/${post.node.slug}/`,
component: additionalPage,
context: {
slug: post.node.slug,
},
});
});
const news = result.data.allContentfulNews.edges;
news.forEach((post) => {
createPage({
path: `/news/${post.node.slug}/`,
component: newsComponent,
context: {
slug: post.node.slug,
},
});
});
});
};