-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
141 lines (131 loc) · 3.38 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const path = require(`path`);
const router = require(`./src/scripts/shared/router`);
exports.sourceNodes = ({
actions: { createNodeField },
getNode,
getNodesByType,
}) => {
/* Relate posts to referencing series */
for (const series of getNodesByType("ContentfulSeries")) {
for (const postId of series.posts___NODE) {
var post = getNode(postId);
createNodeField({ node: post, name: `series`, value: series });
}
}
};
exports.onCreateNode = ({ node, actions, getNodesByType }) => {
/* Link uspecifiers and local analysis files. */
const { createParentChildLink } = actions;
if (
node.internal.type === "File" &&
node.sourceInstanceName === "uspecifiers"
) {
const file = node;
const specifier = getNodesByType("ContentfulUnrealSpecifier").find(
(specifier) => specifier.slug === file.name
);
if (specifier) {
createParentChildLink({ parent: specifier, child: file });
}
}
};
exports.createPages = async ({ graphql, actions, reporter }) => {
const { createPage } = actions;
const query = await graphql(
`
{
posts: allContentfulPost {
nodes {
id
slug
}
}
plugins: allContentfulPlugin {
nodes {
name
}
}
showcases: allContentfulShowcase {
nodes {
id
title
}
}
specifiers: allContentfulUnrealSpecifier {
nodes {
id
key
slug
type
local: childrenFile {
childMarkdownRemark {
frontmatter {
combos
mutex
}
}
}
}
}
}
`
);
if (query.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`);
return;
}
const postTemplate = path.resolve(`./src/components/templates/post.js`);
query.data.posts.nodes.forEach(({ id, slug }) => {
const path = router.getPostSlug(slug);
createPage({
path,
component: postTemplate,
context: {
id: id,
},
});
});
const pluginTemplate = path.resolve(`./src/components/templates/plugin.js`);
query.data.plugins.nodes.forEach(({ name }) => {
const path = router.getProductSlug(name.toLowerCase());
createPage({
path,
component: pluginTemplate,
context: {
name: name,
},
});
});
const showcaseTemplate = path.resolve("./src/components/templates/showcase.js");
query.data.showcases.nodes.forEach((showcase) => {
const path = router.getShowcaseSlug(showcase);
console.log(`Creating showcase page at ${path}`);
createPage({
path,
component: showcaseTemplate,
context: {
id: showcase.id,
},
});
});
const uSpecifierTemplate = path.resolve(`./src/components/templates/uspecifier.js`);
query.data.specifiers.nodes.forEach(({ id, slug, type, key, local }) => {
const { combos, mutex } =
local && local[0] && local[0].childMarkdownRemark
? local[0].childMarkdownRemark.frontmatter
: {};
const path = `/glossary/${slug}`;
createPage({
path,
component: uSpecifierTemplate,
context: {
id: id,
type: type,
key: key,
slug: slug,
combos: combos || [],
mutex: mutex || [],
},
});
});
};