Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(en): add docs for including RSS post content #2129

Merged
merged 8 commits into from
Dec 8, 2022
27 changes: 27 additions & 0 deletions src/pages/en/guides/rss.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,33 @@ export const get = () => rss({
});
```

### Including full post content

By default, the Astro RSS integration does not support including the content of each of your posts in the feed itself.

However, if you create the list of RSS feed objects yourself, you can pass the content of Markdown files (not MDX), to the `content` key using the [`compiledContent` property](/en/guides/markdown-content/#exported-properties). We suggest using a package like [`sanitize-html`](https://www.npmjs.com/package/sanitize-html) in order to make sure that your content is properly sanitized, escaped, and encoded for use in the XML feed.
sarah11918 marked this conversation as resolved.
Show resolved Hide resolved

```js ins={2, 15} title={src/pages/rss.xml.js}
sarah11918 marked this conversation as resolved.
Show resolved Hide resolved
import rss from '@astrojs/rss';
import sanitizeHtml from 'sanitize-html';

// Works with Markdown files only!
const postImportResult = import.meta.glob('../posts/**/*.md', { eager: true });
const posts = Object.values(postImportResult);

export const get = () => rss({
title: 'Buzz’s Blog',
description: 'A humble Astronaut’s guide to the stars',
site: import.meta.env.SITE,
items: posts.map((post) => ({
link: post.url,
title: post.frontmatter.title,
pubDate: post.frontmatter.pubDate,
content: sanitizeHtml(post.compiledContent()),
}))
});
```

## Adding a stylesheet

You can style your RSS feed for a more pleasant user experience when viewing the file in your browser.
Expand Down