mirror of
https://github.com/KazooTTT/kazoottt-blog.git
synced 2025-06-23 10:41:31 +08:00
14 lines
435 B
TypeScript
14 lines
435 B
TypeScript
import getReadingTime from 'reading-time'
|
|
import { toString } from 'mdast-util-to-string'
|
|
|
|
export function remarkReadingTime() {
|
|
// @ts-expect-error:next-line
|
|
return function (tree, { data }) {
|
|
const textOnPage = toString(tree)
|
|
const readingTime = getReadingTime(textOnPage)
|
|
// readingTime.text will give us minutes read as a friendly string,
|
|
// i.e. "3 min read"
|
|
data.astro.frontmatter.minutesRead = readingTime.text
|
|
}
|
|
}
|