You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 lines
963 B

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*/
const crypto = require('crypto');
const createContentDigest = obj =>
crypto
.createHash(`md5`)
.update(obj)
.digest(`hex`);
// Store code snippets in GraphQL for the home page examples.
// Snippets will be matched with markdown templates of the same name.
exports.onCreateNode = async ({actions, node, loadNodeContent}) => {
const {createNode} = actions;
const {absolutePath, ext, name, relativeDirectory, sourceInstanceName} = node;
if (
sourceInstanceName === 'content' &&
relativeDirectory === 'home/examples' &&
ext === '.js'
) {
const code = await loadNodeContent(node);
createNode({
id: name,
children: [],
parent: node.id,
code,
mdAbsolutePath: absolutePath.replace(/\.js$/, '.md'),
internal: {
type: 'ExampleCode',
contentDigest: createContentDigest(JSON.stringify(code)),
},
});
}
};