-
Notifications
You must be signed in to change notification settings - Fork 5
/
gatsby-node.js
69 lines (66 loc) · 2.04 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
const path = require("path")
const pageTemplate = path.resolve(`./src/components/mdxPage.js`)
const postTemplate = path.resolve(`./src/components/mdxPost.js`)
const createMarkdownPages = async (createPage, graphql) => {
const result = await graphql(`
{
allMdx(
filter: { internal: { contentFilePath: { glob: "**/pages/**/*.md" } } }
) {
nodes {
id
internal {
contentFilePath
}
parent {
... on File {
relativePath
}
}
}
}
}
`)
result.data.allMdx.nodes.forEach(node => {
const template = !!node.internal.contentFilePath.match(/\/pages\/posts\//)
? postTemplate
: pageTemplate
const path = node.parent.relativePath
createPage({
path: path.slice(0, path.length - 3),
component: `${template}?__contentFilePath=${node.internal.contentFilePath}`,
context: { id: node.id },
})
})
}
const createRedirectPages = async createPage => {
const links = [
["youtube", "https://www.youtube.com/channel/UCjFqnfg0CKsnQ8ag1MfNtuQ"],
["patreon", "https://shop.otd.ink"],
["shop", "https://shop.otd.ink"],
["twitch", "https://twitch.tv/offthedial"],
["twitter", "https://twitter.com/off_the_dial"],
["github", "https://github.com/offthedial"],
["discord", "https://discord.gg/RDj8axT"],
["tiktok", "https://www.tiktok.com/@offthedial"],
[
"feedback",
"https://docs.google.com/forms/d/e/1FAIpQLSezygI_EfAbPAw-oopfhffRILuJ7WHoSRxUOfFA8nLDBEyhRA/viewform?usp=sf_link"
],
[ "apply", "https://forms.gle/DkkxS6RdxXGobxcx7"],
[ "maps", "https://forms.gle/pk8C9i1X7bT1XjucA"],
]
links.forEach(link => {
createPage({
path: "/" + link[0],
component: path.resolve(`./src/components/Redirect.js`),
context: {
to: link[1],
},
})
})
}
exports.createPages = async ({ graphql, actions: { createPage } }) => {
await createMarkdownPages(createPage, graphql)
await createRedirectPages(createPage, graphql)
}