forked from
quillmatiq.com/augment
Fork of Chiri for Astro for my blog
1import { toString } from 'mdast-util-to-string'
2import getReadingTime from 'reading-time'
3
4/**
5 * Remark plugin to calculate and add reading time information to markdown frontmatter
6 */
7export default function remarkReadingTime() {
8 return function (tree, file) {
9 const textOnPage = toString(tree)
10 const readingTime = getReadingTime(textOnPage)
11
12 const minutes = Math.max(1, Math.round(readingTime.minutes))
13 file.data.astro.frontmatter.minutesRead = `${minutes}min`
14 file.data.astro.frontmatter.readingTime = {
15 text: `${minutes}min`,
16 minutes: minutes,
17 time: readingTime.time,
18 words: readingTime.words
19 }
20 }
21}