-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
196 lines (190 loc) · 4.56 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
const { createRemoteFileNode } = require("gatsby-source-filesystem")
const path = require("path")
const mods = require("./src/data/json-data/mods.json")
const projects = require("./src/data/json-data/projects.json")
const evalImageId = (getNodesByType, image, folder) => {
const localAbsolutePath = path.resolve(__dirname, "src/data/" + folder, image)
let res = getNodesByType("File").find(
(node) =>
node.absolutePath.replace(/\\/g, "/") ===
localAbsolutePath.replace(/\\/g, "/")
)
if (res) {
return res.id
} else {
throw Error("COULD NOT FIND FILE MATCHING " + localAbsolutePath)
}
}
exports.sourceNodes = async ({
actions: {
createRedirect,
createNode,
createNodeField,
createParentChildLink,
},
createNodeId,
createContentDigest,
cache,
store,
getNodesByType,
}) => {
createRedirect({
fromPath: "/twitch",
toPath: "https://twitch.itsmeow.dev/",
isPermanent: true,
})
createRedirect({
fromPath: "/patreon",
toPath: "https://patreon.itsmeow.dev/",
isPermanent: true,
})
createRedirect({
fromPath: "/discord",
toPath: "https://discord.itsmeow.dev/",
isPermanent: true,
})
createRedirect({
fromPath: "/betteranimalsplus",
toPath: "https://betteranimalsplus.com/",
isPermanent: true,
})
createRedirect({
fromPath: "/plugins",
toPath: "/mods",
isPermanent: true,
})
for (let project of projects.list) {
let node = project
node.id = createNodeId(`project-${project.name}`)
node.internal = {
type: "Project",
contentDigest: createContentDigest(project),
}
if (project.image_url) {
node.image___NODE = evalImageId(
getNodesByType,
project.image_url,
"project_image"
)
}
createNode(node)
}
for (let category of mods.categories) {
const { list } = category
let parentNode
{
const { name, title } = category
parentNode = {
name,
title,
id: createNodeId(`project-category-${name}`),
internal: {
type: "ModCategory",
contentDigest: createContentDigest(category),
},
}
createNode(parentNode)
}
for (let card of list) {
const {
name,
title,
role,
info,
sitelink,
customid,
url,
curseforge,
curseforge_game,
spigot,
thunder,
} = card
const node = {
name,
title,
role,
info,
sitelink,
customid,
url,
curseforge,
curseforge_game,
spigot,
thunder,
id: createNodeId(`project-category-${parentNode.name}-project-${name}`),
parent: parentNode.id,
internal: {
type: "Mod",
contentDigest: createContentDigest(card),
},
}
createNode(node)
createParentChildLink({ parent: parentNode, child: node })
if (card.thumbnail_url) {
let remoteNode = await createRemoteFileNode({
url: card.thumbnail_url,
parentNodeId: node.id,
createNode,
createNodeId,
cache,
store,
})
if (remoteNode) {
createNodeField({ node, name: "thumbnail", value: remoteNode.id })
} else {
throw Error("COULD NOT CREATE REMOTE NODE FOR " + card.thumbnail_url)
}
} else if (card.thumbnail_url_local) {
createNodeField({
node,
name: "thumbnail_local",
value: evalImageId(
getNodesByType,
card.thumbnail_url_local,
"thumbnail_local"
),
})
}
}
}
}
exports.createSchemaCustomization = ({ actions: { createTypes } }) => {
createTypes(`
type ModCategory implements Node {
name: String!
title: String!
index: Int!
children: [Mod]
}
type Mod implements Node {
name: String!
title: String!
role: String!
info: String!
thumbnail_url: String
thumbnail_url_local: String
thumbnail: File @link(from: "fields.thumbnail")
thumbnail_local: File @link(from: "fields.thumbnail_local")
sitelink: String
customid: String
curseforge: Boolean
curseforge_game: String
spigot: Boolean
thunder: Boolean
url: String
}
type Project implements Node {
name: String!
description: String!
uses: String!
github: String
download_type: String
download_link: String
youtube_link: String
external_link: String
image_url: String
image: File @link(from: "image___NODE")
image_gif: String
}
`)
}