mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-18 04:06:05 +02:00
feat: markdown extended features from fuwari
This commit is contained in:
parent
9e9cdcb206
commit
5d77abf77c
3 changed files with 57 additions and 34 deletions
|
@ -1 +1,18 @@
|
|||
|
||||
import type { Root } from 'mdast'
|
||||
import type { VFile } from 'vfile'
|
||||
import { toString } from 'mdast-util-to-string'
|
||||
import getReadingTime from 'reading-time'
|
||||
|
||||
export function remarkReadingTime() {
|
||||
return function (tree: Root, file: VFile) {
|
||||
const textOnPage = toString(tree)
|
||||
const readingTime = getReadingTime(textOnPage)
|
||||
|
||||
// 确保 data.astro.frontmatter 存在
|
||||
file.data.astro = file.data.astro || {}
|
||||
file.data.astro.frontmatter = file.data.astro.frontmatter || {}
|
||||
|
||||
file.data.astro.frontmatter.minutes = Math.max(1, Math.round(readingTime.minutes))
|
||||
file.data.astro.frontmatter.words = readingTime.words
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue