-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
70 lines (63 loc) · 1.92 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
58
59
60
61
62
63
64
65
66
67
68
69
70
/* eslint-disable prefer-regex-literals */
const fs = require('fs');
exports.onPreBootstrap = ({ reporter }, options) => {
const contentPath = options.contentPath || 'src/content';
if (!fs.existsSync(contentPath)) {
reporter.info(`creating the ${contentPath} directory`);
fs.mkdirSync(contentPath, { recursive: true });
}
};
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
fallback: {
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
},
},
});
};
exports.createPages = async ({ graphql, actions, reporter }, options) => {
const basePath = options.basePath || '/';
const result = await graphql(`
query {
allMdx {
edges {
node {
id
slug
}
}
}
}
`);
if (result.errors) {
reporter.panic('🚨 ERROR: Loading "createPages" query', reporter.errors);
return;
}
// Adventure Landing Pages & Location Pages
const posts = result.data.allMdx.edges;
// eslint-disable-next-line no-unused-vars
posts.forEach(({ node }, index) => {
const adventureRegex = new RegExp('adventures/\\w+/$');
const locationRegex = new RegExp('adventures/\\w+/locations/');
let template = 'foo';
if (adventureRegex.test(node.slug)) {
template = 'AdventureLandingPage';
}
if (locationRegex.test(node.slug)) {
template = 'LocationPageLayout';
}
if (locationRegex.test(node.slug) || adventureRegex.test(node.slug)) {
actions.createPage({
path: `${basePath}${node.slug}`,
component: require.resolve(`./src/components/${template}/${template}.js`),
context: {
id: node.id,
locations: template === 'AdventureLandingPage' && `${node.slug}locations/`,
npcs: template === 'AdventureLandingPage' && `${node.slug}npcs/`,
},
});
}
});
};