Support Localized sitemaps (using nuxt-i18n)

SnirShechter
0
SnirShechter
commented 7 months 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
0
therddlr
commented 5 months ago

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

0
therddlr
0
therddlr
commented 5 months ago

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

0
Kinvaras
0
Kinvaras
commented 5 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.2k
NicoPennec
commented 3 months ago

@Kinvaras thank you for your help ๐Ÿ™

0
HapLifeMan
0
HapLifeMan
commented 3 days 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
Informations
Feature Request โ€ข Open
#c31 - Created 7 months ago