Skip to content

Conversation

@sgalcheung
Copy link
Owner

@sgalcheung sgalcheung commented Jul 19, 2025

To support Astro 5.9.0 new feat: adds support for rendering markdown in loaders #13850

Compatible with PR: Restrict remark/rehype plugins usage #3274

Implement key code:

const id = item.id;
const parsedData = await parseData({
  id,
  data: JSON.parse(JSON.stringify(item)),
});

const content = item.data?.content?.iv;

store.set({
  id,
  data: parsedData,
  rendered: content ? await renderMarkdown(content) : undefined,
});

This code has a convention that renderMarkdown must specify a markdown field to render, so we assume that the schema you want to cache uses the content field to store markdown content.

Then, you can use the render method as usual for local collection content.

---
import { getEntry, render } from 'astro:content';
const entry = await getEntry('my-collection', Astro.params.id);
const { Content } = await render(entry);
---
<Content />

@changeset-bot
Copy link

changeset-bot bot commented Jul 19, 2025

🦋 Changeset detected

Latest commit: ca494e6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
starsquid Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Jul 19, 2025

Deploy Preview for starsquid failed. Why did it fail? →

Name Link
🔨 Latest commit ca494e6
🔍 Latest deploy log https://app.netlify.com/projects/starsquid/deploys/687bd95e0023f60008456977

@vercel
Copy link

vercel bot commented Jul 19, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
starsquid ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 19, 2025 5:45pm

@sgalcheung sgalcheung changed the title Support RenderMarkdown API feat : Support RenderMarkdown API Jul 19, 2025
@sgalcheung sgalcheung changed the title feat : Support RenderMarkdown API feat: Support RenderMarkdown API Jul 19, 2025
@sgalcheung sgalcheung merged commit 16b17ae into main Jul 19, 2025
4 of 10 checks passed
@sgalreleaseapp sgalreleaseapp bot mentioned this pull request Jul 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant