gatsby-plugin-pathdata
Version:
A gatsby plugin that extracts info from the path of a file
22 lines (17 loc) • 435 B
JavaScript
exports.onCreateNode = (
{ actions, node },
options
) => {
const { type } = node.internal
if (type !== (options.matchNodeType)) return
options.extract.forEach(({ name, selector, replacer }) => {
const value = node.fileAbsolutePath.replace(selector, replacer)
if (value !== null && value !== node.fileAbsolutePath) {
actions.createNodeField({
node,
name,
value,
})
}
})
}