nuxt-community / sitemap-module

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

Nuxt 2 Bridge #281

Open thisismydesign opened 1 year ago

thisismydesign commented 1 year ago

How to make this package work on Nuxt 2 Bridge

There are (at least) 2 things that don't seem to work with Nuxt 2 Bridge:

Working solution

Use patch-package or a fork to rename the hook. You can use my working fork in package.json: "@nuxtjs/sitemap": "thisismydesign/sitemap-module#cd4dc22293b9b67e8ebb5b3c49840e67c108e312"

Use a workaround to copy sitemaps into the static folder rather than relying on a middleware to serve them:

nuxt.config.ts

  hooks: {
    sitemap: {
      generate: {
        done(nuxtInstance) {
          fs.copyFileSync(
            `${nuxtInstance.options.generate.dir}/sitemap.xml`,
            `static/sitemap.xml`
          )
        },
      },
    },
  },

The sitemap is now available at /sitemap.xml

As this is a static file it will only update upon deploy. Keep this in mind for dynamic routes.

How to release this with the package

The hook used and the middleware could be conditional on the dependencies. That would fully support Nuxt 2 Bridge and possibly Nuxt 3 as well.