-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
78 lines (73 loc) · 1.93 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 config = require('./config');
const QRCode = require('qrcode');
const path = require('path');
exports.onCreateBabelConfig = ({ actions }) => {
actions.setBabelPreset({
name: 'babel-preset-gatsby',
options: {
reactRuntime: 'automatic',
},
});
};
exports.createPages = async ({ graphql, actions, reporter }) => {
const res = await graphql(
`
${config.queryContext}
query {
graphCms {
templates${config.isProd ? '(where: { live: true })' : ''} {
...PageInfo
}
metadatas${config.isProd ? '(where: { global: true })' : ''} {
field
listValue
jsonValue
stringValue
numberValue
booleanValue
datetimeValue
}
}
}
`,
);
if (res.errors) {
reporter.panicOnBuild('Error getting resume templates :c');
return;
}
const templates = res.data.graphCms.templates;
const { homepage } = res.data.graphCms.metadatas.reduce((acc, curr) => {
acc[curr.field] =
curr.stringValue ??
curr.numberValue ??
curr.booleanValue ??
curr.datetimeValue ??
curr.jsonValue ??
curr.listValue;
return acc;
}, {});
await Promise.all(
templates.map(async ({ layout, ...resumeInfo }) => {
const pageTemplate = path.resolve(`./src/layouts/${layout}/index.jsx`);
// Too small :c maybe one day we can use this
const qrcode = await QRCode.toString(homepage, {
type: 'svg',
margin: 0,
scale: 2,
});
actions.createPage({
path: `/${resumeInfo?.subdomain ?? ''}`,
component: pageTemplate,
context: {
withButtons: true,
resumeInfo: {
...resumeInfo,
qrcode: qrcode
.replace('#ffffff', 'rgb(var(--page))')
.replace('#000000', 'rgb(var(--text))'),
},
},
});
}),
);
};