master
1import type { RemarkPlugin } from '@astrojs/markdown-remark';
2import { toString } from 'mdast-util-to-string';
3
4export const remarkExcerpt: RemarkPlugin = function () {
5 return (tree, { data }) => {
6 let excerpt = '';
7 for (const node of tree.children) {
8 if (node.type !== 'paragraph') {
9 continue;
10 }
11 excerpt = toString(node);
12 break;
13 }
14 // @ts-expect-error data.astro.frontmatter must be defined
15 data.astro.frontmatter.excerpt = excerpt;
16 };
17};