mirror of
https://github.com/nature-of-code/noc-book-2
synced 2024-11-17 07:49:05 +01:00
46 lines
1,017 B
JavaScript
46 lines
1,017 B
JavaScript
module.exports = async ({
|
|
node,
|
|
actions,
|
|
loadNodeContent,
|
|
createContentDigest,
|
|
createNodeId,
|
|
}) => {
|
|
const { createNodeField, createNode, createParentChildLink } = actions;
|
|
|
|
if (node.internal.mediaType !== `text/html`) {
|
|
return;
|
|
}
|
|
|
|
const { parseContent } = await import('./lib/parse-content.mjs');
|
|
|
|
// load the html source to every HTML file node
|
|
const content = await loadNodeContent(node);
|
|
const { ast, toc, examples } = parseContent(content);
|
|
|
|
createNodeField({
|
|
node,
|
|
name: 'htmlAst',
|
|
value: JSON.stringify(ast),
|
|
});
|
|
|
|
createNodeField({
|
|
node,
|
|
name: 'toc',
|
|
value: JSON.stringify(toc),
|
|
});
|
|
|
|
for (let example of examples) {
|
|
const exampleNode = {
|
|
id: createNodeId(example.relativeDirectory),
|
|
parent: node.id,
|
|
internal: {
|
|
type: 'Example',
|
|
contentDigest: createContentDigest(example),
|
|
},
|
|
...example,
|
|
};
|
|
|
|
createNode(exampleNode);
|
|
createParentChildLink({ parent: node, child: exampleNode });
|
|
}
|
|
};
|