-
Notifications
You must be signed in to change notification settings - Fork 12
/
gatsby-node.js
93 lines (87 loc) · 2.57 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
const fs = require("fs");
const path = require(`path`);
exports.createPages = async ({graphql, actions, reporter}) => {
const {createPage} = actions;
let files = fs.readdirSync("./content");
files.forEach(file => {
if (file.endsWith(".json")) {
let contents = JSON.parse(
fs.readFileSync("./content/" + file, "utf-8")
);
let page_link = "/plugin/" + contents.info.name;
createPage({
path: page_link,
component: require.resolve("./src/templates/pluginTemplate.js"),
context: {
pageContent: contents
}
});
}
});
const articleTemplatePath = path.resolve(
`./src/templates/articlesTemplate.js`
);
const result = await graphql(
`
{
allMarkdownRemark(
sort: {frontmatter: {date: ASC}}
limit: 500
) {
nodes {
id
frontmatter {
slug
}
}
}
}
`
);
if (result.errors) {
reporter.panicOnBuild(
`There was an error loading your blog posts`,
result.errors
);
return;
}
const posts = result.data.allMarkdownRemark.nodes;
// Create pages if there is atleast one
if (posts.length > 0) {
posts.forEach(post => {
createPage({
path: post.frontmatter.slug,
component: articleTemplatePath,
context: {
id: post.id
}
});
});
}
};
exports.sourceNodes = ({actions, createNodeId, createContentDigest}) => {
let files = require("fs");
let examples = [];
examples = JSON.parse(files.readFileSync("./manim_examples.json", "utf8"));
examples.forEach(example => {
let visible = "";
if (example.visible === true) {
visible = "visible";
} else {
visible = "hidden";
}
const node = {
name: example.name,
code: example.code,
output: example.output,
visible: visible,
type: example.type,
id: createNodeId(`ManimExample-${example.name}`),
internal: {
type: "ManimExample",
contentDigest: createContentDigest(examples)
}
};
actions.createNode(node);
});
};