diff options
Diffstat (limited to 'src/plugins/remarkReadingTime.ts')
-rw-r--r-- | src/plugins/remarkReadingTime.ts | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/plugins/remarkReadingTime.ts b/src/plugins/remarkReadingTime.ts new file mode 100644 index 0000000..93f7b00 --- /dev/null +++ b/src/plugins/remarkReadingTime.ts @@ -0,0 +1,11 @@ +import type { RemarkPlugin } from "@astrojs/markdown-remark"; +import { toString } from "mdast-util-to-string"; +import getReadingTime from "reading-time"; + +export function remarkReadingTime(): RemarkPlugin { + return function (tree, { data }) { + const textOnPage = toString(tree); + const readingTime = getReadingTime(textOnPage); + data.astro.frontmatter.minutesRead = readingTime.text; + }; +} |