2018-10-23 14:18:46 +01:00
|
|
|
exports.onCreateNode = function remarkNodeIdentityOnCreateNode(
|
|
|
|
{ node, reporter, actions },
|
|
|
|
{ predicate, identity }
|
|
|
|
) {
|
2018-10-04 14:47:55 +01:00
|
|
|
if (typeof predicate !== 'function') {
|
|
|
|
reporter.panic(
|
|
|
|
'Please supply a predicate function to `gatsby-plugin-identity`'
|
|
|
|
);
|
|
|
|
}
|
2020-02-08 13:29:10 -05:00
|
|
|
if (typeof identity !== 'string' || identity.length === 0) {
|
2018-10-04 14:47:55 +01:00
|
|
|
reporter.panic(
|
|
|
|
'`gatsby-plugin-identity` requires an identify string to add to nodes ' +
|
|
|
|
'that match the predicate'
|
|
|
|
);
|
|
|
|
}
|
2018-10-23 14:18:46 +01:00
|
|
|
const { createNodeField } = actions;
|
2018-10-04 14:47:55 +01:00
|
|
|
if (predicate(node)) {
|
2018-10-23 14:18:46 +01:00
|
|
|
createNodeField({ node, name: 'nodeIdentity', value: identity });
|
2018-10-04 14:47:55 +01:00
|
|
|
}
|
2018-10-23 14:18:46 +01:00
|
|
|
return node;
|
2018-10-04 14:47:55 +01:00
|
|
|
};
|