nuxt-community / sitemap-module

Sitemap Module for Nuxt 2
https://sitemap.nuxtjs.org
MIT License
685 stars 129 forks source link

Support i18n locales options #262

Open tonqa opened 1 year ago

tonqa commented 1 year ago

Currently, I use following config in nuxt.config.js:

  i18n: {
    parsePages: false,
    locales: [
      {
        code: "en",
        iso: "en-US",
        name: "English",
        file: "en.json",
      },
      {
        code: "de",
        iso: "de-DE",
        name: "Deutsch",
        file: "de.json",
      },
    ],
    pages: {
      poetry: {
        en: "/poetry",
        de: "/poesie",
      },
      reports: {
        en: "/reports",
        de: "/berichte",
      },
    },
    strategy: "prefix_and_default",
    defaultLocale: "en",
    vueI18n: {
      baseUrl: "https://eglador.de",
      fallbackLocale: "en",
      silentFallbackWarn: true,
    },
    detectBrowserLanguage: {
      useCookie: true,
      cookieKey: "lang",
      redirectOn: "root",
      alwaysRedirect: true,
    },
    vueI18nLoader: true,
    langDir: "~/locales/",
  },

It seems to me that the sitemap module is slightly confused by the structured locales property. It generates something like this:

    <url>
        <loc>https://mydomain.de/</loc>
        <lastmod>2022-08-07T17:25:50.816Z</lastmod>
        <changefreq>weekly</changefreq>
        <priority>1.0</priority>
        <xhtml:link rel="alternate" hreflang="de" href="https://mydomain.de/de" />
        <xhtml:link rel="alternate" hreflang="en" href="https://mydomain.de/en" />
        <xhtml:link rel="alternate" hreflang="x-default" href="https://mydomain.de/" />
    </url>

It states three alternative xhtml:link elements. Instead it should state only the en locale as a default without the non existing /en/ pathes and the de locale as an alternative to this with the /de/ pathes. Please make that these default options are supported, such that I can start to use your module again.