Sitemap at root level on a multi-language website

I have a website with 3 languages.

Standard Hugo setup generate 4 sitemap.xml
/sitemap.xml => points to the other 3
/en/sitemap.xml => list en pages
/fr/sitemap.xml => list fr pages
/es/sitemap.xml => list es pages

Is there a way to have all pages in one sitemap at root level, instead of having them divided between the various languages?

If it is not possible with sitemap.xml, I am happy with any solution generating XML / JSON, as long as I have all sites pages in a single file.

You will need to create your custom output format for that. The reason the sitemap is generated this way is so that Hugo can concentrate on the real important stuff. This structure enables you to have your language sites in subfolders as well as using the subfolders as subdomain roots. Two birds with one stone. It’s also proper syntax for a sitemap setup.

You can lookup the internal sitemap template and rework it as template for a custom XML output format that outputs all pages in one file.

Custom output format are limited to the directory of each language. I can not manage to get them at root level.

Meanwhile I found a way, by merging sitemapindex and sitemap layouts and using a double loop. Here is the template of sitemapindex if anyone is interested

{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" | safeHTML }}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:xhtml="http://www.w3.org/1999/xhtml">
    {{- range . -}}
        {{ range .Pages }}
  <url>
    <loc>{{ .Permalink }}</loc>{{ if not .Lastmod.IsZero }}
<lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
    <changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
    <priority>{{ .Sitemap.Priority }}</priority>{{ end }}{{ if .IsTranslated }}{{ range .Translations }}
    <xhtml:link
                rel="alternate"
                hreflang="{{ .Lang }}"
                href="{{ .Permalink }}"
                />{{ end }}
    <xhtml:link
                rel="alternate"
                hreflang="{{ .Lang }}"
                href="{{ .Permalink }}"
                />{{ end }}
  </url>
  {{ end }}
    {{- end -}}
</urlset>