-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
58 lines (50 loc) · 1.26 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
const path = require("path");
const fs = require("fs");
exports.createPages = async ({ actions, graphql }) => {
const { createPage } = actions;
const template = path.resolve("./src/templates/tool.js");
const toolPages = fs
.readdirSync("./src/data/tools", { withFileTypes: true })
.filter((item) => !item.isDirectory())
.map((item) => item.name);
toolPages.forEach((tool) => {
const slug = tool.replace(".json", "");
createPage({
path: "/tools/" + slug,
component: template,
context: { slug },
});
});
const textPageTemplate = require.resolve(`./src/templates/text.js`);
await graphql(`
{
allFile(filter: { relativeDirectory: { eq: "text" } }) {
nodes {
id
name
childMarkdownRemark {
html
}
}
}
}
`).then((result) => {
if (result.errors) {
console.error(result.errors);
return Promise.reject(result.errors);
}
return result.data.allFile.nodes.forEach(
({ id, name, childMarkdownRemark: { html } }) => {
createPage({
path: name,
component: textPageTemplate,
context: {
id,
name,
html,
},
});
}
);
});
};