nicco.io/readingTime.js

12 lines
359 B
JavaScript
Raw Permalink Normal View History

2024-11-21 23:42:48 +00:00
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)
2024-12-02 09:45:22 +00:00
data.astro.frontmatter.text = textOnPage
2024-11-21 23:42:48 +00:00
data.astro.frontmatter.readingTime = readingTime
}
}