This repository has been archived by the owner on Nov 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
gatsby-node.js
65 lines (59 loc) · 1.88 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
const path = require("path");
exports.createPages = ({ graphql, actions }) => {
const { createPage, createRedirect } = actions;
const programsTemplate = path.resolve('./src/templates/organizations.js');
const hackersTemplate = path.resolve('./src/templates/hackers.js');
const changelogTemplate = path.resolve('./src/templates/changelog.js');
const glossaryTemplate = path.resolve('./src/templates/glossary.js');
const accessibilityTemplate = path.resolve('./src/templates/accessibility.js');
createRedirect({
fromPath: `/programs/*`,
toPath: `/organizations/*`,
isPermanent: true,
});
return graphql(`
{
allMarkdownRemark(
sort: { order: ASC, fields: [frontmatter___title] }
limit: 1000
) {
edges {
node {
html
frontmatter {
title
path
}
}
}
}
}
`).then(result => {
if (result.errors) {
return Promise.reject(result.errors);
}
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
let template;
if (node.frontmatter.path.includes("/organizations")) {
template = programsTemplate;
createRedirect({
fromPath: node.frontmatter.path.replace("/organizations", "/programs"),
toPath: node.frontmatter.path,
isPermanent: true,
});
} else if (node.frontmatter.path.includes("/hackers")) {
template = hackersTemplate;
} else if (node.frontmatter.path.includes("/changelog")) {
template = changelogTemplate;
} else if (node.frontmatter.path.includes("/glossary")) {
template = glossaryTemplate;
} else if (node.frontmatter.path.includes("/accessibility")) {
template = accessibilityTemplate;
}
createPage({
path: node.frontmatter.path,
component: template,
});
});
});
};