dependabot/npm_and_yarn/sharp-0.35.5
dependabot/npm_and_yarn/astro-7.4.0
dependabot/npm_and_yarn/astrojs/mdx-7.0.8
dependabot/npm_and_yarn/astrojs/sitemap-3.7.4
dependabot/npm_and_yarn/katex-0.19.0
dependabot/npm_and_yarn/prettier-3.9.10
dependabot/npm_and_yarn/sharp-0.35.5
dependabot/npm_and_yarn/tsx-4.23.15
dependabot/npm_and_yarn/typescript-eslint-8.71.2
dependabot/npm_and_yarn/typescript-eslint/parser-8.71.2
development
main
| 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 | } |