forked from newrelic/instant-observability-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
85 lines (77 loc) · 2.22 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
79
80
81
82
83
84
85
const path = require(`path`);
const externalRedirects = require('./src/data/quickstart-redirects.json');
exports.createPages = async ({ actions, graphql, reporter }) => {
const { createPage, createRedirect } = actions;
const result = await graphql(`
query {
allQuickstarts {
edges {
node {
id
slug
}
}
}
}
`);
externalRedirects.forEach(({ from, to }) => {
createRedirect({
fromPath: from,
toPath: to,
isPermanent: true,
});
});
// Handle errors
if (result.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`);
return;
}
const { allQuickstarts } = result.data;
allQuickstarts.edges.forEach(({ node }) => {
const { id, slug } = node;
createPage({
path: path.join(slug, '/'),
component: path.resolve('./src/templates/QuickstartDetails.js'),
context: {
id,
layout: 'QuickStartLayout',
},
});
});
};
exports.onCreatePage = async ({ page, actions }) => {
const { createPage, deletePage } = actions;
const oldPage = { ...page };
if (page.path === '/') {
page.context.layout = 'QuickStartLayout';
}
deletePage(oldPage);
createPage(page);
};
exports.onCreateWebpackConfig = ({ actions, plugins }) => {
actions.setWebpackConfig({
// The `debug` library is causing issues when building the site by including
// invalid JS. This ensures the module resolves to the browser-capatible
// source instead of the node source. See the following issue for this
// recommendation:
// https://github.com/escaladesports/legacy-gatsby-plugin-prefetch-google-fonts/issues/18
plugins: [plugins.normalModuleReplacement(/^\.\/node\.js/, './browser.js')],
externals: {
tessen: 'Tessen',
},
resolve: {
fallback: {
http: false,
https: false,
zlib: false,
},
alias: {
'@components': path.resolve(__dirname, 'src/components/'),
'@hooks': path.resolve(__dirname, 'src/hooks/'),
'@utils': path.resolve(__dirname, 'src/utils/'),
'@layouts': path.resolve(__dirname, 'src/layouts/'),
'@data': path.resolve(__dirname, 'src/data/'),
},
},
});
};