-
Notifications
You must be signed in to change notification settings - Fork 44
/
gatsby-node.js
78 lines (66 loc) · 2.52 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
71
72
73
74
75
76
77
78
const path = require('path');
const { promises: fs } = require('fs');
const packageJson = require('./package.json');
const TEMPLATES_PATH = path.resolve(__dirname, 'src/components/ResumeTemplates');
const disabledTemplates = ['Compact', 'VanHack'];
const ignoredPages = ['/Home/'];
const { convertToKebabCase } = require('./src/utils/gatsby-node-helpers');
const myCreatePage = (createPage, page, pagePath, matchPath, language) => {
createPage({
...page,
path: pagePath,
matchPath,
context: {
...page.context,
intl: {
...page.context.intl,
originalPath: convertToKebabCase(page.context.intl.originalPath),
},
locale: language,
},
});
};
exports.onCreatePage = async ({ page, actions }) => {
const { createPage, deletePage } = actions;
const { locale } = page.context; // from post content
const { language } = page.context.intl; // from accessed site
let matchPath = page.matchPath;
let pagePath = convertToKebabCase(page.path);
deletePage(page);
if (ignoredPages.includes(page.context.intl.originalPath)) {
return;
}
if (page.context.intl.originalPath === '/Build/') {
matchPath = `${pagePath}*`;
}
if (page.context.intl.originalPath === '/ResumeViewer/') {
if (page.internalComponentName === 'ComponentResumeViewer' && language !== 'en') {
return;
}
const templates = await fs.readdir(TEMPLATES_PATH);
templates
.filter((template) => !disabledTemplates.includes(template))
.forEach((template) => {
pagePath = `/view/${template}`.toLocaleLowerCase();
matchPath = `${pagePath}/*`;
myCreatePage(createPage, page, pagePath, matchPath, language);
});
return;
}
myCreatePage(createPage, page, pagePath, matchPath, language);
};
exports.onCreateWebpackConfig = async ({ plugins, actions }) => {
const templates = await fs.readdir(TEMPLATES_PATH);
// TODO this fixes the 'React Refresh Babel' error when NODE_ENV is 'local' for some reason
if (process.env.NODE_ENV !== 'production') {
process.env.NODE_ENV = 'development';
}
actions.setWebpackConfig({
plugins: [
plugins.define({
TEMPLATES_LIST: JSON.stringify(templates.filter((template) => !disabledTemplates.includes(template))),
VERSION: JSON.stringify(packageJson.version),
}),
],
});
};