Sitemap formatting in multilingual sites

I saw this issue while perusing the repo and it also got me curious. Since I switched to multilingual site, the sitemaps under the language folders do not appear properly formatted in the browser, whether locally or on production. But the main sitemap file appears properly formatted. I had an issue where something was causing an error in Google Search Console, and it wasn’t until I viewed the source code of the XML file and the formatting of the source code was as it should be on the file itself. I am not sure if this is a Hugo or browser limitation? Here are examples of Hugo’s own sitemaps.

  1. https://gohugo.io/sitemap.xml - appears correctly formatted.
  2. https://gohugo.io/en/sitemap.xml - appears as one block of minified text.

I used to have this issue on my website when I added EN language. It was related to how some single quotes and double quotes were escaped in sitemap.

I will try to look how I fixed it and let you know tomorrow if that’s also applies to you.

In meantime if you can share your repo to have a look as well.

Actually, your own site appears the same. Just look at your language specific sitemaps. I am using the default Hugo sitemap template, but with modified range.

Could you paste a screenshot showing any error on your/mine?

I know that formating in Edge is different when you load /sitemap.xml and /en/sitemap.xml however Google Search Console and Bing Webmaster don’t see any errors hence need to know what we are looking at as Online validators also don’t see any errors.

You also need to remember that XML files don’t have formatting on its own. Browsers are trying to add a styling. Typically that’s working ok on sitemap in root directory but not in subfolder for multilingual.

There is no issue with sitemap. If is passing validates without errors you shall simply ignore how browsers trying to display them.

I understand that you want to preview them but they are not designed to be accessible this way.

GSC don’t care about formatting and processing Sitemaps correctly and that’s the most important part.

If you want, you can add nice looking styling by using this for example (not tested):

Error was not related to the sitemap itself, but an issue with empty links in this implementation which were appearing in the sitemap, hence the gist of my original question.

So, this is a browser issue? Hmm…The browsers are unable to output the document tree for the multilingual sitemaps, so checking the source code is the only way to view the tree properly.

Will test this and see if it works. I liked it back when I used WP I could style the sitemap. I have had a few requests to do it for a site I co-author with friends that I migrated to Hugo.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.