Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions;
if (node.internal.type === `MarkdownRemark`) {
const value = createFilePath({ node, getNode });
createNodeField({
name: `slug`,
node,
value,
});
// Create additional fields if it is a part of docs
if (mm.isMatch(node.fileAbsolutePath, '**/docs/*/*.md')) {
const type = mm.capture(
`${__dirname}/docs/*/*.md`,
node.fileAbsolutePath
);
if (type && type[0]) {
createNodeField({
name: 'docType',
node,
value: type[0],
});
}
}
}
};
options.rules.some(rule => {
const result = mm.capture(rule.pattern, filepath, options.matchOptions);
if (!result) {
return false;
}
const value = interpolate(rule.to, result);
replaceNode(scope, options.baseUri + value);
return true;
});
}