skip to Main Content

So I’m currently implementing sitemaps for a website that features multiple store fronts.

I used nuxt sitemap module to generate a /sitemap/sitemap.xml file for the static pages, like homepage, terms and conditions and privacy policy.

Now the website also contains dynamic routes for every store front, for example: mysite.com/store1 & mysite.com/store2

The current task is to create a /sitemap.xml for each store, so the end result is something like: mysite.com/store1/sitemap.xml

This sitemap will contain everything related to the store, including dynamic subroutes of each product.

I’m currently not aware of any possible way to do this, and I’ve searched a lot but I couldn’t find anything on this. Any ideas?

2

Answers


  1. You can create a sitemap index as follows:

    {
      sitemap: {
        hostname: 'https://example.com',
        path: '/sitemap.xml',
        sitemaps: [
          {
            path: '/sitemap/sitemap.xml',
          },
          {
            path: '/store1/sitemap.xml',
            exclude: ['/**'],
            routes: () => { /* return array of url for store #1 */ }
          },
          {
            path: '/store2/sitemap.xml',
            exclude: ['/**'],
            routes: () => { /* return array of url for store #2 */ }
          }
        ]
      }
    }
    

    You will have this result:

    • /sitemap.xml => the sitemap index (the entry point for crawlers)
    • /sitemap/sitemap.xml => all static routes
    • /store1/sitemap.xml => only dynamic routes for store #1
    • /store2/sitemap.xml => only dynamic routes for store #2
    Login or Signup to reply.
  2. Try this, it worked for me

      sitemap: {
        path: '/sitemap.xml',
        hostname: process.env.BASE_URL,
        cacheTime: 1000 * 60 * 15,
        gzip: true,
        generate: false,
        sitemaps: [
          {
            path: '/sitemap/sitemap.xml',
          },
          {
            path: '/store1/sitemap.xml',
            exclude: [],
            routes: async () => {
                let apiUrl = 'your site url' // or API url
                const { data } = await axios.get(`${apiUrl}store1`)
                return data.data.map(v => `/${v.id}`)
              }
          },
          {
            path: '/store2/sitemap.xml',
            exclude: [],
            routes: async () => {
                let apiUrl = 'your site url' // or API url
                const { data } = await axios.get(`${apiUrl}store2`)
                return data.data.map(v => `/${v.id}`)
              }
          },
          {
            path: '/store3/sitemap.xml',
            exclude: [],
            routes: async () => {
                let apiUrl = 'your site url' // or API url
                const { data } = await axios.get(`${apiUrl}store3`)
                return data.data.map(v => `/${v.id}`)
              }
          },
        ]
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search