-
Notifications
You must be signed in to change notification settings - Fork 3
/
gatsby-node.js
52 lines (47 loc) · 1.18 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
const { graphql } = require('gatsby');
const path = require('path');
// create member pages
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const result = await graphql(`
query {
allMembersJson {
nodes {
en {
name
}
fr {
name
}
parent {
id
}
}
}
allFile(
filter: {extension: {eq: "json"}, relativeDirectory: {eq: "content/members"}}
) {
nodes {
name
id
}
}
}
`);
result.data.allMembersJson.nodes.forEach((node) => {
const member = node.en.name;
const { id } = node.parent;
const slug = result.data.allFile.nodes.find((node) => node.id === id).name.substring(3);
Object.keys(node).forEach((key) => {
if (key !== 'parent') {
const language = key;
const template = 'MemberPage.js';
createPage({
path: `${language === 'en' ? '' : '/fr'}/members/${slug}`,
component: path.resolve(`./src/templates/${template}`),
context: { slug, language, member },
});
}
});
});
};