The property exclude VS generate:route priority

Aylay
0
Aylay
commented 4 months ago

What problem does this feature solve?

Hi all ;)

In my nuxt file, I have an array of URL in generate:routes which contain multiple url and my 404 URL.
Also, I put this same 404 URL in the array of sitemap:exclude.

But, the 404 URL is always in my sitemap.xml.

Is it possible to force the exclude property of the generate sitemap property ?

Thanks

What does the proposed changes look like?

If any URL is in the exclude property and the generate:routes property, keep removing the URL in the exclude property

idea
0
NicoPennec
1.7k
NicoPennec
commented 4 months ago

Hi @Aylay

I'm not sure I understand your feature request.
According to your comment, it seems a bug on the exclude option

The sitemap module doesn't properly exclude your route 404, right?

if so, can you provide a sample of code (or, even better, a github project ^^) to reproduce your issue, please?

0
Aylay
0
Aylay
commented 4 months ago

Hi @NicoPennec ,

You're totally right :)

My project is on Bitbucket ;)

Here is some code in my nuxt.config.js :

module.exports = {
  modules: [
    '@nuxtjs/pwa',
    '@nuxtjs/sitemap'
  ],
  generate: {
    routes: [
      '/404',
      '/pause-cafe/creation-developpement-site-internet',
      '/pause-cafe/objectifs-publicites-facebook'
    ]
  },
  sitemap: {
    hostname: appURL,
    gzip: true,
    exclude: [
      '/merci',
      '/404',
      '404'
    ]
  }
}

Is there an order putting module in the file ?

The first url in my sitemap.xml is /404 ;)

Thanks

0
NicoPennec
1.7k
NicoPennec
commented 4 months ago

The sitemap.exclude option is only for static routes (see https://github.com/nuxt-community/sitemap-module/#exclude-optional)

Furthermore, If you don't set the sitemap.routes option for dynamic routes, the sitemap-module will initialize the value by default with the generate.routes value (see https://github.com/nuxt-community/sitemap-module/#routes)

So, the simple way to solve your issue is to init the sitemap.routes option with the requested routes.

eg.

module.exports = {
  modules: [
    '@nuxtjs/pwa',
    '@nuxtjs/sitemap'
  ],
  generate: {
    routes: [
      '/404',
      '/pause-cafe/creation-developpement-site-internet',
      '/pause-cafe/objectifs-publicites-facebook'
    ]
  },
  sitemap: {
    hostname: appURL,
    gzip: true,
    exclude: [
      '/merci'
    ],
    routes: [
      '/pause-cafe/creation-developpement-site-internet',
      '/pause-cafe/objectifs-publicites-facebook'
    ]
  }
}

Another way is to use the sitemap.filter option to exclude the "/404/" path

eg.

{
  sitemap: {
    filter ({ routes }) {
      return routes.filter(route => route.url !== '/404')
    }
  }
}
0
Informations
Feature Request โ€ข Open
#c58 - Created 4 months ago