-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
38 lines (31 loc) · 974 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
require(`dotenv`).config({
path: `.env`,
})
const axios = require('axios');
const get = endpoint =>
axios.get(`${process.env.API_ROOT}${endpoint}`);
exports.createPages = async ({ actions: { createPage } }) => {
const { data: articles } = await get('articles/');
let publishedArticles = articles;
// omit post if labeled a draft in production
if (!(process.env.NODE_ENV === 'development')) {
publishedArticles = publishedArticles.filter(
article => article.isPublished
);
}
// Create a page that lists all Articles
createPage({
path: '/',
component: require.resolve('./content/templates/home.jsx'),
context: { articles: publishedArticles },
});
// // Create a page for each post.
publishedArticles.forEach(article => {
// console.log(article)
createPage({
path: `/article/${article.id}/`,
component: require.resolve('./content/templates/blog-post.js'),
context: { article },
});
});
};