-
Notifications
You must be signed in to change notification settings - Fork 29
/
gatsby-node.js
207 lines (183 loc) · 5.33 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
197
198
199
200
201
202
203
204
205
206
207
const path = require(`path`);
const fetch = require("node-fetch");
const fs = require("file-system");
// Add URLs to v2 indexes to this array for them to be rendered on the website
// If the index does not need to be downloaded, place the index.yaml in src/data/indexes
// Note: this is only for developement add URLs to /ci/get-indexes.sh to affect production
const indexURLs = [
"https://github.com/appsody/stacks/releases/latest/download/stable-index.yaml",
"https://github.com/appsody/stacks/releases/latest/download/incubator-index.yaml",
"https://github.com/appsody/stacks/releases/latest/download/experimental-index.yaml"
];
const { createFilePath } = require(`gatsby-source-filesystem`);
exports.createPages = ({ actions, graphql }) => {
const { createPage, createRedirect } = actions;
// Redirects section
// The CLI reference has moved and is now a top level menu item
createRedirect({
fromPath: `/docs/using-appsody/cli-commands`,
toPath: `/docs/cli-commands`,
isPermanent: true
});
// The install doc was split and placed under its own installing menu
createRedirect({
fromPath: `/docs/getting-started/installation`,
toPath: `/docs/installing/installing-appsody`,
isPermanent: true
});
// The getting-started doc was moved to the top level menu
createRedirect({
fromPath: `/docs/getting-started/quick-start`,
toPath: `/docs/getting-started`,
isPermanent: true
});
// The modify doc was merged with the create doc to form a develop doc
createRedirect({
fromPath: `/docs/stacks/modify`,
toPath: `/docs/stacks/develop`,
isPermanent: true
});
// The create doc was merged with the modify doc to form a develop doc
createRedirect({
fromPath: `/docs/stacks/create`,
toPath: `/docs/stacks/develop`,
isPermanent: true
});
// The stack structure doc was merged into the stack overview doc
createRedirect({
fromPath: `/docs/stacks/stack-structure`,
toPath: `/docs/stacks/stacks-overview`,
isPermanent: true
});
// The environment variables page has moved from the stacks section to reference
createRedirect({
fromPath: `/docs/stacks/environment-variables`,
toPath: `/docs/reference/environment-variables`,
isPermanent: true
});
// The building and deploying doc was split into multiple docs
createRedirect({
fromPath: `/docs/using-appsody/building-and-deploying`,
toPath: `/docs/using-appsody/deploying`,
isPermanent: true
});
const docTemplate = path.resolve(`src/templates/docTemplate.js`);
const blogTemplate = path.resolve(`src/templates/blogTemplate.js`);
const tutorialTemplate = path.resolve(`src/templates/tutorialTemplate.js`);
return graphql(`
{
docs: allMarkdownRemark(
filter: {fileAbsolutePath: {regex: "//docs//"}}
) {
edges {
node {
fileAbsolutePath
fields {
slug
}
}
}
},
blogs: allMarkdownRemark(
filter: {fileAbsolutePath: {regex: "//blogs//"}}
) {
edges {
node {
fileAbsolutePath
fields {
slug
}
}
}
},
tutorials: allMarkdownRemark(
filter: {fileAbsolutePath: {regex: "//tutorials//"}}
) {
edges {
node {
fileAbsolutePath
fields {
slug
}
}
}
}
}
`).then(result => {
if (result.errors) {
return Promise.reject(result.errors);
}
const { docs, blogs, tutorials } = result.data;
docs.edges.forEach(({ node }) => {
if (node.fields.slug == "/docs/overview/") {
node.fields.slug = "/docs";
}
createPage({
path: node.fields.slug,
component: docTemplate,
context: {
pagePath: node.fields.slug
}
});
});
blogs.edges.forEach(({ node }) => {
createPage({
path: node.fields.slug,
component: blogTemplate,
context: {
pagePath: node.fields.slug
}
});
});
tutorials.edges.forEach(({ node }) => {
createPage({
path: node.fields.slug,
component: tutorialTemplate,
context: {
pagePath: node.fields.slug
}
});
});
});
};
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
if (node.internal.type === `MarkdownRemark`) {
const slug = createFilePath({ node, getNode });
if (slug == "/overview/") {
createNodeField({
node,
name: `slug`,
value: `/docs`
});
} else if ((node.frontmatter.author !== undefined) && (node.frontmatter.tutorial === undefined)) {
createNodeField({
node,
name: `slug`,
value: `/blogs${slug}`
});
} else if (node.frontmatter.tutorial === "true") {
createNodeField({
node,
name: `slug`,
value: `/tutorials${slug}`
});
} else {
createNodeField({
node,
name: `slug`,
value: `/docs${slug}`
});
}
}
};
exports.onPreInit = () => {
indexURLs.forEach(url => {
fetch(url)
.then(res => res.text())
.then(body => {
const fileName = url.split("/").reverse()[0];
fs.writeFile(`src/data/indexes/${fileName}`, body);
});
});
};