From ca357079a38d455953d99c5e8aa2c109ce7efb6d Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Thu, 1 Dec 2022 00:06:41 -0800 Subject: [PATCH 1/7] docs(en): add docs for including RSS post content --- src/pages/en/guides/rss.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/pages/en/guides/rss.md b/src/pages/en/guides/rss.md index aab2c11e2e04e..1520d669423bc 100644 --- a/src/pages/en/guides/rss.md +++ b/src/pages/en/guides/rss.md @@ -114,6 +114,34 @@ export const get = () => rss({ }); ``` +### Adding the post's content to the feed + +By default, the Astro RSS integration does not support including the content of each of your posts in the feed itself. However, if you choose option 2 above to create a list of RSS feed objects yourself, you can pass the content of your post to the `content` key to add it to the feed, so long as you pass it HTML that has been properly sanitized and escaped. The `compiledContent` function that is returned on each post from the call to `import.meta.glob` will return the content of your markdown already processed as HTML by Astro. All you need to do at that point is run it through a package like [sanitize-html](https://www.npmjs.com/package/sanitize-html) in order to make sure that it is properly escaped and encoded to use in the XML feed. + +:::note +This feature is currently only supported with Markdown files, _not_ MDX. See the API for [Astro.glob() (which uses import.meta.glob under the hood](/en/guides/markdown-content/#exported-properties) to see the full list of properties are supported for Markdown, MDX, or both. +::: + +```js ins={2, 15} title={src/pages/rss.xml.js} +import rss from '@astrojs/rss'; +import sanitizeHtml from 'sanitize-html'; + +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. From 0661557526a0f1269f80ef963bdcf3e8f0ea733e Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Mon, 5 Dec 2022 16:14:40 -0800 Subject: [PATCH 2/7] incorporate @sarah11918's revisions Co-authored-by: Sarah Rainsberger --- src/pages/en/guides/rss.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pages/en/guides/rss.md b/src/pages/en/guides/rss.md index 1520d669423bc..b7f1f82877d4a 100644 --- a/src/pages/en/guides/rss.md +++ b/src/pages/en/guides/rss.md @@ -114,19 +114,18 @@ export const get = () => rss({ }); ``` -### Adding the post's content to the feed +### 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 choose option 2 above to create a list of RSS feed objects yourself, you can pass the content of your post to the `content` key to add it to the feed, so long as you pass it HTML that has been properly sanitized and escaped. The `compiledContent` function that is returned on each post from the call to `import.meta.glob` will return the content of your markdown already processed as HTML by Astro. All you need to do at that point is run it through a package like [sanitize-html](https://www.npmjs.com/package/sanitize-html) in order to make sure that it is properly escaped and encoded to use in the XML feed. +By default, the Astro RSS integration does not support including the content of each of your posts in the feed itself. -:::note -This feature is currently only supported with Markdown files, _not_ MDX. See the API for [Astro.glob() (which uses import.meta.glob under the hood](/en/guides/markdown-content/#exported-properties) to see the full list of properties are supported for Markdown, MDX, or both. -::: +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. 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. ```js ins={2, 15} title={src/pages/rss.xml.js} import rss from '@astrojs/rss'; import sanitizeHtml from 'sanitize-html'; -const postImportResult = import.meta.glob('../posts/**/*.md', { eager: true }); +// Works with Markdown files only! +const postImportResult = import.meta.glob('../posts/**/*.md', { eager: true }); const posts = Object.values(postImportResult); export const get = () => rss({ From 62c300085aad12b6967770a4364aff80f0e9eb37 Mon Sep 17 00:00:00 2001 From: Sarah Rainsberger Date: Tue, 6 Dec 2022 18:54:01 -0400 Subject: [PATCH 3/7] punctuation, formatting --- src/pages/en/guides/rss.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/en/guides/rss.md b/src/pages/en/guides/rss.md index b7f1f82877d4a..9056911b52b93 100644 --- a/src/pages/en/guides/rss.md +++ b/src/pages/en/guides/rss.md @@ -118,7 +118,7 @@ export const get = () => rss({ 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. 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. +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. 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. ```js ins={2, 15} title={src/pages/rss.xml.js} import rss from '@astrojs/rss'; From 6a9dfb28629d4b9fd54c77fd32bec93804d56400 Mon Sep 17 00:00:00 2001 From: Sarah Rainsberger Date: Tue, 6 Dec 2022 18:59:24 -0400 Subject: [PATCH 4/7] mention compiledContent explicitly --- src/pages/en/guides/rss.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/en/guides/rss.md b/src/pages/en/guides/rss.md index 9056911b52b93..997983b7aff56 100644 --- a/src/pages/en/guides/rss.md +++ b/src/pages/en/guides/rss.md @@ -118,7 +118,7 @@ export const get = () => rss({ 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. 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. +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. ```js ins={2, 15} title={src/pages/rss.xml.js} import rss from '@astrojs/rss'; From 5c9c566eb487e345b7c36bc1c4409747f2160344 Mon Sep 17 00:00:00 2001 From: Sarah Rainsberger Date: Tue, 6 Dec 2022 19:00:09 -0400 Subject: [PATCH 5/7] highlight correct line after edits --- src/pages/en/guides/rss.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/en/guides/rss.md b/src/pages/en/guides/rss.md index 997983b7aff56..905e540091296 100644 --- a/src/pages/en/guides/rss.md +++ b/src/pages/en/guides/rss.md @@ -120,7 +120,7 @@ By default, the Astro RSS integration does not support including the content of 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. -```js ins={2, 15} title={src/pages/rss.xml.js} +```js ins={2, 16} title={src/pages/rss.xml.js} import rss from '@astrojs/rss'; import sanitizeHtml from 'sanitize-html'; From 565bfaee1073b6ff33d638ca486b9aedd9f84f26 Mon Sep 17 00:00:00 2001 From: Sarah Rainsberger Date: Tue, 6 Dec 2022 19:57:49 -0400 Subject: [PATCH 6/7] a change that functions to give chris co-author cred... Co-authored-by: Chris Swithinbank --- src/pages/en/guides/rss.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/en/guides/rss.md b/src/pages/en/guides/rss.md index 905e540091296..3024f4f66e205 100644 --- a/src/pages/en/guides/rss.md +++ b/src/pages/en/guides/rss.md @@ -118,7 +118,7 @@ export const get = () => rss({ 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. +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. ```js ins={2, 16} title={src/pages/rss.xml.js} import rss from '@astrojs/rss'; From 19b75ff40bca49f45594278555277eb8645c83d2 Mon Sep 17 00:00:00 2001 From: delucis Date: Thu, 8 Dec 2022 18:50:46 +0100 Subject: [PATCH 7/7] Add `` component --- src/pages/en/guides/rss.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/en/guides/rss.md b/src/pages/en/guides/rss.md index 3024f4f66e205..401055899d26b 100644 --- a/src/pages/en/guides/rss.md +++ b/src/pages/en/guides/rss.md @@ -3,7 +3,9 @@ layout: ~/layouts/MainLayout.astro title: RSS description: An intro to RSS in Astro i18nReady: true -setup: import PackageManagerTabs from '~/components/tabs/PackageManagerTabs.astro' +setup: | + import PackageManagerTabs from '~/components/tabs/PackageManagerTabs.astro'; + import Since from '~/components/Since.astro'; --- Astro supports fast, automatic RSS feed generation for blogs and other content websites. For more information about RSS feeds in general, see [aboutfeeds.com](https://aboutfeeds.com/). @@ -116,6 +118,8 @@ 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.