Support Localized sitemaps (using nuxt-i18n)

SnirShechter
0
SnirShechter
commented 2 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 a month ago

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

0
therddlr
0
therddlr
commented a month ago

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

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