Skip to content

Commit

Permalink
fix: generate sitemap from an absolute path
Browse files Browse the repository at this point in the history
eg. `sitemap: { path: /sitemap.xml }`
  • Loading branch information
Nicolas Pennec committed May 10, 2019
1 parent 6629952 commit 78f1f32
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [],
Expand Down Expand Up @@ -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, ''))
Expand Down
1 change: 1 addition & 0 deletions test/fixture/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
},
modules: ['@@'],
sitemap: {
path: '/sitemap.xml',
exclude: [
'/exclude'
],
Expand Down

0 comments on commit 78f1f32

Please sign in to comment.