出于学习目的,我编写了一个反转节点内容的 Gatsby 转换器。我将它与 一起使用gatsby-source-filesystem
,仅对.test
文件进行操作:
const crypto = require(`crypto`)
module.exports = function onCreateNode({ node, loadNodeContent, boundActionCreators }) {
const { createNode, createParentChildLink } = boundActionCreators;
if (node.extension !== 'test') {
return;
}
const nodeContent = loadNodeContent(node);
const nodeContentRev = nodeContent.split('').reverse().join('');
const contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(nodeContent))
.digest(`hex`);
const RevNode = {
'contentRev': nodeContentRev,
id: '9087657865-just-something-here-for-now',
parent: null,
children: [],
internal: {
type: 'Rev',
contentDigest,
content,
},
};
createNode(RevNode);
}
不幸的是,我对 Gatsby 还是很陌生,所以我很难确定这是否有效。看看官方的变形金刚,他们不仅实现gatsby-node.js
了(这就是我所拥有的),而且还实现了extend-node-type.js
,但我找不到任何关于此的文档。
如何查询变压器的结果?