mirror of
https://github.com/saicaca/fuwari.git
synced 2026-01-12 23:32:53 +01:00
feat: use the first paragraph as the excerpt if description is not set
This commit is contained in:
16
src/plugins/remark-excerpt.js
Normal file
16
src/plugins/remark-excerpt.js
Normal 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
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user