Skip to content

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

@gislerro

Description

@gislerro

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions