Localized sitemap links duplicating

miguelskeeled
5
miguelskeeled
commented 4 months ago

Hi,

I'm trying to implement a localized sitemap following Google's instructions (https://webmasters.googleblog.com/2012/05/multilingual-and-multinational-site.html). I managed to add the localized links to the sitemap like the following example:

<url> <loc>https://www.example.com/customers</loc> <xhtml:link rel="alternate" hreflang="de" href="https://www.example.com/de/kunden" /> <xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/en/customers" /> <xhtml:link rel="alternate" hreflang="fr" href="https://www.example.com/fr/clients" /> <xhtml:link rel="alternate" hreflang="nl" href="https://www.example.com/nl/klanten" /> </url>

The problem is that after having this <url> entry, it is also generating the following <url> entries:
<url> <loc>https://www.example.com/customers</loc> </url> <url> <loc>https://www.example.com/fr/clients</loc> </url> <url> <loc>https://www.example.com/nl/klanten</loc> </url> <url> <loc>https://www.example.com/de/kunden</loc> </url>

In my website, all the pages are multilanguage so I included all my routes in the routes property of the sitemap in nuxt.config.js, and all the routes are having this duplication issue.

This is my sitemap configuration:
sitemap: { path: '/sitemap.xml', hostname: 'https://www.example.com', cacheTime: 1000 * 60 * 15, gzip: true, generate: true, routes: sitemapLinks(), }

This sitemapLinks is a synchronous function that returns an array of objects and each object has the following structure:

{ url: '/customers', links: [ { lang: 'de', url: 'de/kunden' }, { lang: 'en', url: 'customers' }, { lang: 'fr', url: 'fr/clients' }, { lang: 'nl', url: 'nl/klanten' } ]}

I have a CMS's API which I call when I run my app. This call retrieves all the pages I have in my website, and I put these routes in a static file. I then use this static file to generate the links for the sitemap routes property, to generate the pages of nuxt-i18n and also to generate the components dynamically for each page on router extendRoutes property.

I also included this module after the nuxt-i18n in nuxt.config.js.

So my problem is that basically, I'm sending all my routes with the structure showed previously to the routes property of the sitemap module, the module is generating the localized sitemap correctly, but then duplicates all the routes with a different structure in the sitemap. Am I doing anything wrong or am I missing anything?

0
NicoPennec
1.4k
NicoPennec
commented 4 months ago

hi @miguelskeeled
I'm not sure to understand. Can you share an extract of your current sitemap.xml ?
Do want you remove from the sitemap all static routes generated by nuxt-i18n ? if yes, see exclude option: https://github.com/nuxt-community/sitemap-module#exclude-optional

1
miguelskeeled
5
miguelskeeled
commented 4 months ago

Hi @NicoPennec
Yes, I wanted to remove those static routes generated by nuxt-i18n and indeed I started experimenting the exclude option and managed to accomplish what I wanted.

exclude: Object.keys(locales).map(locale => '/${locale}/**') - this configuration on the exclude option did what I wanted.

Thanks for your help,
Cheers

1
Informations
Question โ€ข Unresolved
#c45 - Created 4 months ago