From 1dadd24d4795304077f70fb90a69354780538442 Mon Sep 17 00:00:00 2001 From: Tommy Palmer Date: Wed, 28 Feb 2024 22:06:16 +0000 Subject: [PATCH] Clarify how to add images to the RSS feed --- src/content/docs/en/guides/rss.mdx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/content/docs/en/guides/rss.mdx b/src/content/docs/en/guides/rss.mdx index 8b27bea01e6e5..ef50a84ace144 100644 --- a/src/content/docs/en/guides/rss.mdx +++ b/src/content/docs/en/guides/rss.mdx @@ -165,7 +165,7 @@ The `content` key contains the full content of the post as HTML. This allows you A package like [`sanitize-html`](https://www.npmjs.com/package/sanitize-html) will make sure that your content is properly sanitized, escaped, and encoded. In the process, such a package might also remove some harmless elements and attributes, so make sure to verify the output and configure the package according to your needs. ::: -When using content collections, render the post `body` using a standard Markdown parser like [`markdown-it`](https://github.com/markdown-it/markdown-it) and sanitize the result: +When using content collections, render the post `body` using a standard Markdown parser like [`markdown-it`](https://github.com/markdown-it/markdown-it) and sanitize the result, including any extra tags (e.g. ``) needed to render your content: ```js title="src/pages/rss.xml.js" ins={3, 4, 5, 16} import rss from '@astrojs/rss'; @@ -183,7 +183,9 @@ export async function GET(context) { items: blog.map((post) => ({ link: `/blog/${post.slug}/`, // Note: this will not process components or JSX expressions in MDX files. - content: sanitizeHtml(parser.render(post.body)), + content: sanitizeHtml(parser.render(post.body), { + allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']) + }), ...post.data, })), });