I'm working on upgrading a site from using Markdown files in src/pages to using content collections, starting with blog posts. Each blog post has an excerpt which is used in lists. In the past, the excerpt was separated from the rest of the post using a <!--MORE--> comment, which was manually parsed out to find the index:
Begin with the excerpt
<!--MORE-->
Continue with the rest of the posts
The pages were imported using import.meta.glob() which generated a MarkdownInstance, so I could render the HTML of the excerpt using the compiledContent() function:
async function getExcerptOfPost<T extends Record<string, any>>(md: MarkdownInstance<T>): Promise<string> {
const content = await md.compiledContent();
return content.slice(0, content.indexOf("<!-- MORE -->"));
}
<Fragment set:html={getExcerptOfPost(post)}/>
With the new Content Collection I have moved the excerpts to a new excerpt property in the frontmatter. They're still Markdown, but currently typed as z.string(), and I can't think of a good way to render it to Markdown. Does it count as "External Markdown", and do I need to somehow extend the file loader to get access to renderMarkdown()? I could return to the <!--MORE--> system, but it's unpopular with users so I would prefer the excerpt property approach.