summaryrefslogtreecommitdiff
path: root/src/plugins/remark-reading-time.ts
blob: 843dde11b554215c0f9d8c63cd7f25f1bd7984ca (plain)
1
2
3
4
5
6
7
8
9
10
11
import { toString as mdastToString } from "mdast-util-to-string";
import getReadingTime from "reading-time";

export function remarkReadingTime() {
	// @ts-expect-error:next-line
	return (tree, { data }) => {
		const textOnPage = mdastToString(tree);
		const readingTime = getReadingTime(textOnPage);
		data.astro.frontmatter.readingTime = readingTime.text;
	};
}