Skip to content
Permalink
Browse files

feat: add "xmlNs" option to set custom XML namespaces

  • Loading branch information...
NicoPennec committed May 10, 2019
1 parent a45de6f commit 751a779cf6b12982291f829bf0c9be68d4968f03
Showing with 23 additions and 0 deletions.
  1. +15 −0 README.md
  2. +4 −0 lib/module.js
  3. +1 −0 test/fixture/nuxt.config.js
  4. +3 −0 test/module.test.js
@@ -127,6 +127,21 @@ Examples:
Enable the creation of the `.xml.gz` sitemap compressed with gzip.
### `xmlNs` (optional)
- Default: `undefined`
Set the XML namespaces by override all default `xmlns` attributes in `<urlset>` element.
```js
// nuxt.config.js
{
sitemap: {
xmlNs: 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'
}
}
```
### `xslUrl` (optional)
- Default: `undefined`
@@ -20,6 +20,7 @@ module.exports = function module (moduleOptions) {
cacheTime: 1000 * 60 * 15,
filter: undefined,
gzip: false,
xmlNs: undefined,
xslUrl: undefined,
defaults: {}
}
@@ -173,6 +174,9 @@ function createSitemap (options, routes, req) {
// Set cacheTime
sitemapConfig.cacheTime = options.cacheTime || 0

// Set XML namespaces
sitemapConfig.xmlNs = options.xmlNs

// Set XSL url
sitemapConfig.xslUrl = options.xslUrl

@@ -21,6 +21,7 @@ module.exports = {
],
filter: ({ routes }) =>
routes.filter(route => route.url !== '/filtered'),
xmlNs: 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"',
xslUrl: 'sitemap.xsl',
defaults: {
changefreq: 'daily',
@@ -83,6 +83,9 @@ describe('ssr', () => {
// filtered routes
expect(xml).not.toContain('<loc>http://localhost:3000/filtered</loc>')

// custom XML namespaces
expect(xml).toContain('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')

// custom XSL
expect(xml).toContain('<?xml-stylesheet type="text/xsl" href="sitemap.xsl"?>')

0 comments on commit 751a779

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