-
Notifications
You must be signed in to change notification settings - Fork 13
/
gatsby-node.js
126 lines (110 loc) · 3.83 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
const data = require("./src/mimeData.json")
/**
* @type {import("gatsby").GatsbyNode["createPages"]}
*/
exports.createPages = async ({ actions }) => {
const { createPage } = actions
const templateWeb = require.resolve(
"./src/shared/templates/MimetypeTemplate.tsx"
)
if (!templateWeb) {
throw new Error("templateWeb not found")
}
data.forEach(mimeObject => {
var path = mimeObject.name
// Create MimeData for page
const pageMimeData = {
...mimeObject,
templateData: {
deprecatedBy: null,
parentType: null,
},
}
createPage({
path,
component: templateWeb,
context: pageMimeData,
})
const appearsAs = mimeObject.appearsAs ? mimeObject.appearsAs : []
if (pageMimeData.links.deprecates) {
// Create pages for deprecated mimetypes
for (const deprecatedTypeName of pageMimeData.links.deprecates) {
// Create MimeData for page
const deprecatedPageMimeData = {
...mimeObject,
path: deprecatedTypeName,
name: deprecatedTypeName,
templateData: {
deprecatedBy: pageMimeData.name,
parentType: pageMimeData.name,
},
}
createPage({
path: deprecatedTypeName,
component: templateWeb,
context: deprecatedPageMimeData,
})
}
}
// Create child pages using same MimeData with no deprecatedBy warning
for (const childTypeName of pageMimeData.links.parentOf) {
// Create MimeData for page
const alternativePageMimeData = {
...mimeObject,
path: childTypeName,
name: childTypeName,
templateData: {
deprecatedBy: null,
parentType: pageMimeData.name,
},
}
const newAlternativesList = [
mimeObject.name,
...appearsAs.filter(m => m !== childTypeName),
...(mimeObject.alternatives || []),
]
createPage({
path: childTypeName,
component: templateWeb,
context: alternativePageMimeData,
})
}
// Create child pages using same MimeData with no deprecatedBy warning
for (const alternativeTypeName of pageMimeData.links.alternativeTo) {
// Create MimeData for page
const alternativePageMimeData = {
...mimeObject,
path: alternativeTypeName,
name: alternativeTypeName,
templateData: {
deprecatedBy: null,
parentType: null,
},
}
const newRelatedList = [
mimeObject.name,
...pageMimeData.links.relatedTo.filter(
m => m !== alternativeTypeName
),
]
const newAlternativesList = [
mimeObject.name,
...pageMimeData.links.alternativeTo.filter(
m => m !== alternativeTypeName
),
]
createPage({
path: alternativeTypeName,
component: templateWeb,
context: {
...alternativePageMimeData,
links: {
...pageMimeData.links,
relatedTo: newRelatedList,
alternativeTo: newAlternativesList,
},
},
})
}
})
}