-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
67 lines (63 loc) · 1.7 KB
/
gatsby-node.js
File metadata and controls
67 lines (63 loc) · 1.7 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const fs = require('fs-extra');
const path = require('path');
const createPaginatedPages = require('gatsby-paginate');
global.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators;
const Blog = path.resolve(`src/templates/blog.js`);
const postTemplate = path.resolve(`src/templates/single-post.js`);
return new Promise(resolve => {
graphql(`
{
posts: allMarkdownRemark(
sort: { fields: [frontmatter___date], order: DESC }
) {
edges {
node {
id
html
excerpt
frontmatter {
title
path
author
date
}
}
}
}
}
`).then(result => {
const EDGES = result.data.posts.edges;
createPaginatedPages({
edges: EDGES,
createPage,
pageTemplate: Blog,
pageLength: 10,
pathPrefix: 'blog',
context: {},
buildPath: (index, pathPrefix) =>
index > 1 ? `${pathPrefix}/${index}` : `/${pathPrefix}`, // This is optional and this is the default
});
EDGES.map(({ node }) =>
createPage({
path: node.frontmatter.path,
component: postTemplate,
context: {},
})
);
resolve();
});
});
};
exports.onPostBootstrap = () => {
fs.copySync(
path.join(__dirname, '/src/locales'),
path.join(__dirname, '/public/locales')
);
};
exports.modifyWebpackConfig = config => {
const configuration = config;
configuration.devtool = 'source-map';
return config;
};