From 0d6725c26743194972cd04d46759e9fab0997f41 Mon Sep 17 00:00:00 2001 From: f33w <139555788+f33w@users.noreply.github.com> Date: Wed, 24 Apr 2024 17:48:48 +0300 Subject: [PATCH] Update rss.mdx (#7878) Co-authored-by: Luiz Ferraz Co-authored-by: Sarah Rainsberger --- src/content/docs/en/guides/rss.mdx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/content/docs/en/guides/rss.mdx b/src/content/docs/en/guides/rss.mdx index 56d8185026745..385fe9fd51ce9 100644 --- a/src/content/docs/en/guides/rss.mdx +++ b/src/content/docs/en/guides/rss.mdx @@ -214,6 +214,30 @@ export function GET(context) { } ``` +## Removing trailing slashes + +Astro's RSS feed produces links with a trailing slash by default, no matter what value you have configured for `trailingSlash`. This means that your RSS links may not match your post URLs exactly. + +If you have set `trailingSlash: "never"` on your `astro.config.mjs`, set `trailingSlash: false` in the `rss()` helper so that your feed matches your project configuration. + +```ts title="src/pages/rss.xml.js" ins={9} +import rss from '@astrojs/rss'; + +export function GET(context) { + const posts = Object.values(postImportResult); + return rss({ + title: 'Buzz’s Blog', + description: 'A humble Astronaut’s guide to the stars', + site: context.site, + trailingSlash: false, + items: posts.map((post) => ({ + link: post.url, + ...post.frontmatter, + })), + }); +} +``` + ## Adding a stylesheet Style your RSS feed for a more pleasant user experience when viewing the file in your browser.