gatsby-remark-reading-time
Version:
Adds an estimated reading time field to all remark nodes
20 lines (18 loc) • 472 B
JavaScript
;
const readingTime = require("reading-time");
exports.onCreateNode = ({ node, actions }) => {
const { createNodeField } = actions;
if (node.internal.type === `MarkdownRemark`) {
createNodeField({
node,
name: `readingTime`,
value: readingTime(node.rawMarkdownBody)
});
} else if (node.internal.type === `Mdx`) {
createNodeField({
node,
name: `readingTime`,
value: readingTime(node.rawBody)
});
}
};