Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/content/docs/zh-cn/guides/rss.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ items: import.meta.glob('./blog/*.{md,mdx}'),
:::

当使用内容集合时,使用标准的 Markdown 解析器如 [`markdown-it`](https://github.com/markdown-it/markdown-it) 渲染文章 `body` 并清理结果:
在使用内容集合时,使用标准的 Markdown 解析器如 [`markdown-it`](https://github.com/markdown-it/markdown-it) 渲染文章 `body` 并清理结果,包括渲染内容所需的任何额外标签(例如 `<img>`):

```js title="src/pages/rss.xml.js" ins={3, 4, 5, 16}
import rss from '@astrojs/rss';
Expand All @@ -182,7 +183,9 @@ export async function GET(context) {
items: blog.map((post) => ({
link: `/blog/${post.slug}/`,
// 注意:这不会处理 MDX 文件中的组件或 JSX 表达式。
content: sanitizeHtml(parser.render(post.body)),
content: sanitizeHtml(parser.render(post.body), {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img'])
}),
...post.data,
})),
});
Expand Down