-
Notifications
You must be signed in to change notification settings - Fork 34
/
gatsby-node.js
177 lines (164 loc) · 4.22 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
const { createFilePath } = require(`gatsby-source-filesystem`);
const kebabCase = require('lodash/kebabCase');
const has = require('lodash/has');
const {
BLOGS_QUERY,
PLUGINS_QUERY,
TAGS_QUERY,
LEGAL_NOTICES_QUERY,
DOCS_QUERY,
CASE_STUDIES_QUERY,
CHANGELOG_QUERY,
BACKSTAGE_BITES_QUERY,
} = require('./src/queries/gatsbyNodeQueries');
const createLatestLegalNotices = require('./src/pageCreation/createLatestLegalNotices');
const createPagesFromQuery = require('./src/pageCreation/createPagesFromQuery');
const createListPagesFromQuery = require('./src/pageCreation/createListPagesFromQuery');
const transformPageFrontmatter = require('./src/pageCreation/transformPageFrontmatter');
exports.createPages = async ({ graphql, actions }) => {
await createPagesFromQuery({
templatePath: './src/templates/BlogPost.js',
query: BLOGS_QUERY,
resultName: 'blogs.edges',
actions,
graphql,
processor: ({ node }, component) => {
return {
path: node.slug,
component,
context: {
slug: node.slug,
},
};
},
});
await createPagesFromQuery({
templatePath: './src/templates/Tag.js',
query: TAGS_QUERY,
resultName: 'tagsGroup.group',
actions,
graphql,
processor: ({ fieldValue }, component) => ({
path: `/tags/${kebabCase(fieldValue)}/`,
component,
context: {
tag: fieldValue,
},
}),
});
await createPagesFromQuery({
templatePath: './src/templates/Plugin.js',
query: PLUGINS_QUERY,
resultName: 'plugins.edges',
actions,
graphql,
processor: ({ node }, component) => ({
path: node.fields.slug,
component,
context: {
slug: node.fields.slug,
},
}),
});
await createPagesFromQuery({
templatePath: './src/templates/LegalNotice.js',
query: LEGAL_NOTICES_QUERY,
resultName: 'notices.edges',
actions,
graphql,
processor: ({ node }, component) => ({
path: node.fields.slug,
component,
context: {
slug: node.fields.slug,
},
}),
});
await createPagesFromQuery({
templatePath: './src/templates/Doc.js',
query: DOCS_QUERY,
resultName: 'docs.edges',
actions,
graphql,
processor: ({ node }, component) => ({
path: node.fields.slug,
component,
context: {
slug: node.fields.slug,
},
}),
});
await createPagesFromQuery({
templatePath: './src/templates/BackstageBite.js',
query: BACKSTAGE_BITES_QUERY,
resultName: 'videos.edges',
actions,
graphql,
processor: ({ node }, component) => ({
path: `/backstage-bites/${node.slug}/`,
component,
context: {
slug: node.slug,
},
}),
});
await createPagesFromQuery({
templatePath: './src/templates/CaseStudy.js',
query: CASE_STUDIES_QUERY,
resultName: 'caseStudies.edges',
actions,
graphql,
processor: ({ node }, component) => {
return {
path: `/case-studies/${node.slug}/`,
component,
context: {
slug: node.slug,
},
};
},
});
await createListPagesFromQuery({
templatePath: './src/templates/ChangelogList.js',
query: CHANGELOG_QUERY,
actions,
graphql,
basePath: '/changelog/',
itemsPerPage: 20,
});
await createPagesFromQuery({
templatePath: './src/templates/ChangeSet.js',
query: CHANGELOG_QUERY,
resultName: 'result.edges',
actions,
graphql,
basePath: '/changelog/',
processor: ({ node }, component) => {
return {
path: `/changelog/${node.slug}/`,
component,
context: {
slug: node.slug,
},
};
},
});
await createLatestLegalNotices({
graphql,
actions,
});
};
exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions;
// has(node, 'fileAbsolutePath') prevents this code from running on nodes which come
// from the Contentful CMS, rather than the local filesystem.
if (node.internal.type === `MarkdownRemark` && has(node, 'fileAbsolutePath')) {
node = transformPageFrontmatter({ node });
const value = createFilePath({ node, getNode });
createNodeField({
name: `slug`,
node,
value,
});
}
};