forked from newrelic/instant-observability-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
81 lines (71 loc) · 1.96 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
const path = require(`path`);
const resolveQuickstartSlug = require('./src/utils/resolveQuickstartSlug.js');
exports.createPages = async ({ actions, graphql, reporter }) => {
const { createPage } = actions;
const result = await graphql(`
query {
allQuickstarts {
edges {
node {
fields {
slug
}
id
}
}
}
}
`);
// Handle errors
if (result.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`);
return;
}
const { allQuickstarts } = result.data;
allQuickstarts.edges.forEach(({ node }) => {
const {
fields: { slug },
id,
} = 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.onCreateNode = ({ node, actions }) => {
const { createNodeField } = actions;
if (node.internal.type === 'Quickstarts') {
createNodeField({
node,
name: 'slug',
value: `${resolveQuickstartSlug(node.name, node.id)}`,
});
}
};
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',
},
});
};