-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
54 lines (49 loc) · 1.4 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
const path = require('path');
const gql = require('graphql-tag');
const { print } = require('graphql/language/printer');
const LOAD_ALL_MDX_QUERY = print(gql`
query LoadAllMdx {
allMdx(
filter: { fields: { draft: { eq: false } } }
) {
edges {
node {
frontmatter {
title
date
slug
}
}
}
}
}
`);
// https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#createPages
exports.createPages = async ({ graphql: useQuery, actions, reporter }) => {
const { createPage } = actions;
const postTemplate = path.resolve('src/templates/post.tsx');
const result = await useQuery(LOAD_ALL_MDX_QUERY);
if (result.errors) {
reporter.panicOnBuild('Error while running GraphQL query.');
throw new Error(result.errors);
}
result.data.allMdx.edges.forEach(({ node }) => {
const { slug } = node.frontmatter;
createPage({
path: slug,
component: postTemplate,
context: {
slug,
},
});
});
};
// https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/#onCreateWebpackConfig
// https://www.gatsbyjs.com/docs/how-to/custom-configuration/add-custom-webpack-config/#absolute-imports
exports.onCreateWebpackConfig = ({ stage, actions }) => {
actions.setWebpackConfig({
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
},
});
};