blog/plugin/remark-reading-time.ts
Michael Zhang 4a89b35ba3
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
ok kinda working
2023-08-31 03:07:03 -05:00

12 lines
422 B
TypeScript

import getReadingTime from "reading-time";
import { toString } from "mdast-util-to-string";
export function remarkReadingTime() {
return function (tree, { data }) {
const textOnPage = toString(tree);
const readingTime = getReadingTime(textOnPage);
// readingTime.text will give us minutes read as a friendly string,
// i.e. "3 min read"
data.astro.frontmatter.minutesRead = readingTime.text;
};
}