Files
freeCodeCamp/tools/client-plugins/gatsby-remark-node-identity/gatsby-node.js
Oliver Eyton-Williams 69d6ee32bf feat: python in the browser (#50913)
Co-authored-by: Beau Carnes <1513130+beaucarnes@users.noreply.github.com>
2023-07-28 07:36:25 +02:00

22 lines
643 B
JavaScript

exports.onCreateNode = function remarkNodeIdentityOnCreateNode(
{ node, reporter, actions },
{ predicate, identity }
) {
if (typeof predicate !== 'function') {
reporter.panic(
'Please supply a predicate function to `gatsby-remark-node-identity`'
);
}
if (typeof identity !== 'string' || identity.length === 0) {
reporter.panic(
'`gatsby-remark-node-identity` requires an identify string to add to nodes ' +
'that match the predicate'
);
}
const { createNodeField } = actions;
if (predicate(node)) {
createNodeField({ node, name: 'nodeIdentity', value: identity });
}
return node;
};