withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.78k stars 2.48k forks source link

@astrojs/rss uses trailing slash on home page when it shouldn't #10994

Closed patrickreiner closed 6 months ago

patrickreiner commented 6 months ago

Astro Info

Astro                    v4.8.2
Node                     v20.12.1
System                   macOS (arm64)
Package Manager          npm
Output                   hybrid
Adapter                  @astrojs/vercel/serverless
Integrations             @astrojs/sitemap

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

In my astro.config.mjs I set:

export default defineConfig({ ... trailingSlash: 'never', })

and in my vercel.json I set:

{ "cleanUrls": true, ... "trailingSlash": false }

and in my rss.xml.js I set:

export async function GET(context) { return rss({ trailingSlash: false, }) }

and yet, the RSS feed still puts a slash on the home page, viewable here:

http://astro-rss-trailing-slash.patrickreiner.com/rss.xml

What's the expected result?

RSS home page should not have a trailing slash.

Should be:

https://astro-rss-trailing-slash.patrickreiner.com

Not:

https://astro-rss-trailing-slash.patrickreiner.com/

Link to Minimal Reproducible Example

https://github.com/patrickreiner/astro-rss-trailing-slash

Participation

BryceRussell commented 6 months ago

Hello! 👋

There was a discussion about this on another issue here: https://github.com/withastro/astro/issues/10723#issuecomment-2051625034

In summary: The urls are treated as the same, there is no difference between https://example.com and https://example.com/ except visual

mingjunlu commented 6 months ago

@BryceRussell Thanks! I somehow missed that issue

BryceRussell commented 6 months ago

@mingjunlu No worries!

@patrickreiner I am going to go ahead and close this since this is expected behavior. If you have any other issues feel free to open another issue 😀

patrickreiner commented 6 months ago

Hi @BryceRussell, thank you, I agree with your label of "nice to have" where it's not breaking anything, but it would be nice to have the visual consistency. @astrojs/sitemap for example used to work like this as well (where the home page always had a trailing backslash) but that behavior was recently corrected as you can see here https://astro-rss-trailing-slash.patrickreiner.com/sitemap-0.xml

BryceRussell commented 6 months ago

You're right! Sorry, I did not realize the sitemap had a similar change recently and did not consider that this could be changed even if it is only visual. For reference, there is a workflow for triaging issues that I try to follow, but I am still learning 😅 I will re-open this issue

BryceRussell commented 6 months ago

It looks like this issue happens because the links are transformed from a string, to a URL, and then back to a string

https://github.com/withastro/astro/blob/a78fa266850a0c8e0b42a0909eacbd577483b9f6/packages/astro-rss/src/util.ts#L20

https://github.com/withastro/astro/blob/a78fa266850a0c8e0b42a0909eacbd577483b9f6/packages/astro-rss/src/index.ts#L219-L224

Example:

// Returns 'http://example.com/'
new URL('http://example.com').toString()
V3RON commented 6 months ago

@BryceRussell That's exactly the reason. I'm willing to work on it if you don't mind 😉

Fryuni commented 6 months ago

For awareness, the recent change on the sitemap was not just cosmetic like it is here; in that case, it affects SEO by having the canonical URL of a page mismatched between the page and the sitemap.