forked from stellar/new-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
73 lines (69 loc) · 1.61 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
const path = require("path");
const {
createMdxPages,
getFileName,
getLocale,
} = require("./buildHelpers/createMdxPages");
exports.onCreateNode = ({ node, actions }) => {
const { createNodeField } = actions;
const filename = getFileName(node);
if (filename) {
// For any MDX files, we want to know if they have a locale associated with
// them. Pull it from the filename.
const locale = getLocale(filename);
createNodeField({
node,
name: "locale",
value: locale,
});
}
if (node.internal.type === "Mdx" && node.fileAbsolutePath) {
const value = path.parse(
path.relative("./", node.fileAbsolutePath).split("docs")[1],
).dir;
console.log(
node.fileAbsolutePath,
path.relative("./", node.fileAbsolutePath).split("docs")[1],
);
createNodeField({
node,
name: "path",
value,
});
}
};
exports.createPages = async ({ graphql, actions }) => {
const result = await graphql(
`
{
allMdx {
edges {
node {
id
fileAbsolutePath
fields {
locale
path
}
}
}
}
}
`,
);
if (result.errors) {
console.log(result.errors);
return Promise.reject(result.errors);
}
const mdxFiles = result.data.allMdx.edges;
console.log(mdxFiles);
createMdxPages({ actions, mdxFiles });
};
// Enable absolute imports from `src/`
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
modules: ["node_modules", "src"],
},
});
};