-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgatsby-node.js
70 lines (65 loc) · 1.77 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
const path = require('path');
exports.onCreateWebpackConfig = ({ actions, stage }) => {
actions.setWebpackConfig({
resolve: {
modules: [path.join(__dirname, 'src'), 'node_modules'],
alias: {
'~components': path.resolve(__dirname, 'src/components'),
'~utils': path.resolve(__dirname, 'src/utils'),
},
},
});
};
exports.onCreateNode = ({ node, actions: { createNodeField } }) => {
if (node.internal.type === 'kontent_item_person') {
const hasNotes = node.elements.pinned_notes.value.length > 0;
createNodeField({
node,
name: `hasNotes`,
value: hasNotes,
});
}
};
exports.createPages = ({ graphql, actions: { createPage } }) => {
return new Promise((resolve, _reject) => {
graphql(`
query peoplePortalList {
allKontentItemPerson(
filter: { elements: { list_in_portal: { value: { elemMatch: { codename: { eq: "yes" } } } } } }
) {
nodes {
elements {
urlslug {
value
}
}
preferred_language
}
}
}
`).then(
({
data: {
allKontentItemPerson: { nodes },
},
}) => {
for (const person of nodes) {
let lang = `${person.preferred_language}/`;
if (person.preferred_language === 'en') {
lang = '/';
}
let pagePath = `${lang}employees/${person.elements.urlslug.value}`;
createPage({
path: pagePath,
component: path.resolve(`./src/templates/person.js`),
context: {
slug: person.elements.urlslug.value,
lang: person.preferred_language,
},
});
}
resolve();
}
);
});
};