@smbcloud / fatapp-web Mirror · read-only
Fork 0

Read-only mirror of github.com/smbcloudXYZ/fatapp-web.

Mirrored from https://github.com/smbcloudXYZ/fatapp-web.git

Synced Nov 25, 09:15 UTC

1 import { toString } from 'mdast-util-to-string'
2 import getReadingTime from 'reading-time'
3
4 /**
5 * Remark plugin to calculate and add reading time information to markdown frontmatter
6 */
7 export 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 }