forked from navikt/sykdom-i-familien
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
83 lines (73 loc) · 2.32 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
'use strict';
require('dotenv').config();
require('source-map-support').install();
const svgoProps = require('./gatsbyUtils/svgoProps');
const SVGO = require('svgo');
const Sites = require('./build-utils/sites');
const svgo = new SVGO(svgoProps);
require('ts-node').register({
compilerOptions: {
module: 'commonjs',
target: 'es2017',
},
});
const pageCreator = require('./build-utils/create-pages');
const createPagesForSite = async (site, onlyPublicPages, { graphql, actions }) => {
await pageCreator.createPages(
'allSanityYtelsePage',
site,
onlyPublicPages,
{ graphql, actions },
'./src/templates/ytelsePageTemplate.tsx'
);
await pageCreator.createPages(
'allSanityCustomPage',
site,
onlyPublicPages,
{ graphql, actions },
'./src/templates/customPageTemplate.tsx'
);
await pageCreator.createPages(
'allSanitySectionPage',
site,
onlyPublicPages,
{ graphql, actions },
'./src/templates/sectionPageTemplate.tsx'
);
};
exports.createPages = async (tools) => {
const onlyPublicPages = process.env.ENV !== 'dev';
console.log('onlyPublicPages:', onlyPublicPages);
await createPagesForSite(Sites.sif, onlyPublicPages, tools);
await createPagesForSite(Sites.arbeidsgiver, onlyPublicPages, tools);
await createPagesForSite(Sites.samarbeid, onlyPublicPages, tools);
};
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
externals: {
canvas: 'commonjs canvas',
},
});
};
async function onCreateNode({ node, actions, createNodeId, createContentDigest }) {
if (node.internal.type !== 'SanityIllustration') {
return;
}
if (node.svg) {
const optimizedSvg = await svgo.optimize(node.svg);
const svgNode = {
id: createNodeId(`svgo-${node.id}`),
svg: optimizedSvg.data,
children: [],
parent: node.id,
internal: {
contentDigest: createContentDigest({}),
type: 'optimizedSvg',
},
};
const { createNode, createParentChildLink } = actions;
createNode(svgNode);
createParentChildLink({ parent: node, child: svgNode });
}
}
exports.onCreateNode = onCreateNode;