feat: use the first paragraph as the excerpt if description is not set

This commit is contained in:
saicaca
2024-08-03 16:03:03 +08:00
parent 9af6cf956a
commit 1f93499ece
3 changed files with 20 additions and 3 deletions

View File

@@ -0,0 +1,16 @@
import { toString } from 'mdast-util-to-string'
/* Use the post's first paragraph as the excerpt */
export function remarkExcerpt() {
return (tree, { data }) => {
let excerpt = '';
for (let node of tree.children) {
if (node.type !== 'paragraph') {
continue
}
excerpt = toString(node)
break
}
data.astro.frontmatter.excerpt = excerpt
};
}