Skip to content
Permalink
Browse files

fix: generate sitemap from an absolute path

eg. `sitemap: { path: /sitemap.xml }`
  • Loading branch information...
NicoPennec committed May 10, 2019
1 parent 6629952 commit 78f1f3268165cf819243e4954544c6984d9dcec3
Showing with 5 additions and 4 deletions.
  1. +1 −1 README.md
  2. +3 −3 lib/module.js
  3. +1 −0 test/fixture/nuxt.config.js
@@ -66,7 +66,7 @@ The `routes` parameter follows the same way than the `generate` [configuration](
See as well the [routes](#routes-1) examples below.
### `path` (optional)
- Default: `sitemap.xml`
- Default: `/sitemap.xml`
The URL path of the generated sitemap.
@@ -13,7 +13,7 @@ const defaultPublicPath = '/_nuxt/'

module.exports = function module (moduleOptions) {
const defaults = {
path: 'sitemap.xml',
path: '/sitemap.xml',
hostname: this.options.build.publicPath !== defaultPublicPath ? this.options.build.publicPath : undefined,
exclude: [],
routes: this.options.generate.routes || [],
@@ -77,13 +77,13 @@ module.exports = function module (moduleOptions) {
const routes = await cache.get('routes')
const sitemap = await createSitemap(options, routes)
const xml = await sitemap.toXML()
const xmlGeneratePath = path.resolve(this.options.generate.dir, options.path)
const xmlGeneratePath = path.join(this.options.generate.dir, options.path)
await fs.ensureFile(xmlGeneratePath)
await fs.writeFile(xmlGeneratePath, xml)
consola.success('Generated', xmlGeneratePath.replace(this.options.generate.dir, ''))
if (options.gzip) {
const gzip = await sitemap.toGzip()
const gzipGeneratePath = path.resolve(this.options.generate.dir, options.pathGzip)
const gzipGeneratePath = path.join(this.options.generate.dir, options.pathGzip)
await fs.ensureFile(gzipGeneratePath)
await fs.writeFile(gzipGeneratePath, gzip)
consola.success('Generated', gzipGeneratePath.replace(this.options.generate.dir, ''))
@@ -9,6 +9,7 @@ module.exports = {
},
modules: ['@@'],
sitemap: {
path: '/sitemap.xml',
exclude: [
'/exclude'
],

0 comments on commit 78f1f32

Please sign in to comment.
You can’t perform that action at this time.