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

(sitemap) Root site URL in generated sitemap does not respect AstroConfig.trailingSlash #10751

Closed
1 task done
gislerro opened this issue Apr 11, 2024 · 3 comments · Fixed by #10772
Closed
1 task done
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@gislerro
Copy link
Contributor

gislerro commented Apr 11, 2024

Astro Info

Astro                    v4.5.18
Node                     v18.18.0
System                   Linux (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             @astrojs/sitemap

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

No response

Describe the Bug

Using this Astro Config:

import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';

export default defineConfig({
	site: 'https://example.com',
	trailingSlash: 'never',
	integrations: [sitemap()],
});

results in the following sitemap-0.xml being generated after astro build on a basic setup two pages index.astro and about.astro:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
   xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
   xmlns:xhtml="http://www.w3.org/1999/xhtml"
   xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
   xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
   <url>
      <loc>https://example.com/</loc>
   </url>
   <url>
      <loc>https://example.com/about</loc>
   </url>
</urlset>

What's the expected result?

All urls in the generated sitemap conform to the trailingSlash config option:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
   xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"
   xmlns:xhtml="http://www.w3.org/1999/xhtml"
   xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
   xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
   <url>
      <loc>https://example.com</loc>
   </url>
   <url>
      <loc>https://example.com/about</loc>
   </url>
</urlset>

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-6n4cpf?file=dist%2Fsitemap-0.xml

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Apr 11, 2024
@gislerro
Copy link
Contributor Author

After some investigating this seems to be an upstream issue in sitemap.js. I could implement the workaround suggested if it's desired

@ematipico
Copy link
Member

I believe we could attempt to apply the workaround. @gislerro, would you like to send a PR?

@matthewp matthewp added - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs triage Issue needs to be triaged labels Apr 12, 2024
@tholyong
Copy link

Hi, is there a way to maintain a trailing slash for the root URL even when AstroConfig.trailingSlash is 'never'? The majority of the browsers will land/redirect the root URL with a trailing slash (although we can't see it, but when we copy the URL the trailing slash is included). So in the Sitemap and for a better SEO practice, it is probably a good idea to have the root URL with the trailing slash included even when AstroConfig.trailingSlash is 'never'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants