Support Localized sitemaps (using nuxt-i18n)

SnirShechter
3
SnirShechter
commented a year ago

What problem does this feature solve?

There is no way of automatically generating a sitemap when the site is localized (using nuxt-i18n, for example).

Two difficulties when using the sitemap module with the nuxt-i18n localization:

  1. Prefixes ('/en').
  2. Url localization (/en/shop becomes /fr/boutique or so).

What does the proposed changes look like?

I suggest (if in any way possible) to generate the static pages using the router routes after they were already generated by the nuxt-i18n module.

idea
0
therddlr
3
therddlr
commented 10 months ago

I am looking for the same feature. Pretty frustrating that it's missing.

0
therddlr
3
therddlr
commented 10 months ago

Ideally if nuxt-i18n is return all urls that we can then use.

0
Kinvaras
0
Kinvaras
commented 10 months ago

Hi,

I had the same problem recently, in a project using nuxt-i18n. The problem is the sitemap module doesn't take care of dynamically generated routes in a localized context. With no extra options for the nuxt sitemap module in nuxt.config.js, my sitemap was well defined. But adding a simple option to the module broke the generation up. Actually, it seems like module declaration order in your nuxt.config.js is important.

You have to inject it after the i18n nuxt module.

For example:

// nuxt.config.js

module.exports = {
// ...
  modules: [
    '@nuxtjs/sitemap',
    [
      'nuxt-i18n',
      require('./config/i18n'),
    ],
  ],
  sitemap: require('./config/sitemap'),
// ...
}

With the following "config/sitemap.js", it works as expected:

// config/sitemap.js

module.exports = {};

While it doesn't with the following:

// config/sitemap.js

module.exports = {
  path: '/sitemap.xml',
  hostname: process.env.BASE_URL,
  exclude: [
    '/en/**',
    '/es/**',
  ],
};

But if you inject the sitemap module like this:

// nuxt.config.js

module.exports = {
// ...
  modules: [
    [
      'nuxt-i18n',
      require('./config/i18n'),
    ],
    '@nuxtjs/sitemap', // Notice the order
  ],
  sitemap: require('./config/sitemap'),
// ...
}

It works in both case !
Tell me if it solves your problem or if I misunderstood your issue.

Cheers

0
NicoPennec
1.4k
NicoPennec
commented 8 months ago

@Kinvaras thank you for your help ๐Ÿ™

0
HapLifeMan
0
HapLifeMan
commented 5 months ago

It can be very interesting if an option can generate different sitemap files for every locale, maybe by defining an array for each sitemap or directly integrated with i18n.

Then we can reference these files in the robots.txt ๐Ÿ™‚

0
antimodern
0
antimodern
commented 5 months ago

As far I as I know this module doesnt not support multiple sitemaps?

0
NicoPennec
1.4k
NicoPennec
commented 5 months ago

@bdrtsky not yet, but in the roadmap in short term

0
Informations
Feature Request โ€ข Open
#c31 - Created a year ago