-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.ts
48 lines (45 loc) · 1.25 KB
/
gatsby-node.ts
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
import { Cite } from "@citation-js/core";
import { GatsbyNode } from "gatsby";
import { createFilePath } from "gatsby-source-filesystem";
require("@citation-js/plugin-bibtex");
export const onCreateNode: GatsbyNode["onCreateNode"] = async ({
node,
actions,
loadNodeContent,
createNodeId,
createContentDigest,
getNode,
}) => {
const { createNode, createParentChildLink, createNodeField } = actions;
if (node.extension === `bib`) {
const content = await loadNodeContent(node);
const parsedContent = new Cite(content, {
generateGraph: false,
forceType: "@biblatex/text",
maxChainLength: 100,
}).data;
parsedContent
.map((entry) => {
return {
...entry,
id: createNodeId(`${node.id} ${entry.id} >>> Citation`),
children: [],
parent: node.id,
internal: {
contentDigest: createContentDigest(entry),
type: `Citation`,
},
};
})
.forEach((data) => {
createNode(data);
createParentChildLink({ parent: node, child: data });
});
} else if (node.internal.type === "MarkdownRemark") {
createNodeField({
node,
name: "slug",
value: createFilePath({ node, getNode }),
});
}
};