mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 19:51:07 +02:00
21 lines
573 B
TypeScript
21 lines
573 B
TypeScript
import type { Root } from 'mdast'
|
|
import type { VFile } from 'vfile'
|
|
import { toString } from 'mdast-util-to-string'
|
|
|
|
export function remarkExcerpt() {
|
|
return function (tree: Root, file: VFile) {
|
|
let excerpt = ''
|
|
for (const node of tree.children) {
|
|
if (node.type === 'paragraph') {
|
|
excerpt = toString(node)
|
|
break
|
|
}
|
|
}
|
|
|
|
// 确保 data.astro.frontmatter 存在
|
|
file.data.astro = file.data.astro || {}
|
|
file.data.astro.frontmatter = file.data.astro.frontmatter || {}
|
|
|
|
file.data.astro.frontmatter.excerpt = excerpt
|
|
}
|
|
}
|