Skip to content
Permalink
Browse files

feat: add "xslUrl" option to set a custom XSL file to style the sitemap

fix #58
  • Loading branch information...
NicoPennec committed May 1, 2019
1 parent 56fdddd commit de1b7069fa967e1bc6d30ffca225729fdfd99ec7
Showing with 13 additions and 0 deletions.
  1. +5 −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,11 @@ Examples:
Enable the creation of the `.xml.gz` sitemap compressed with gzip.
### `xslUrl` (optional)
- Default: `undefined`
The URL path of the XSL file to style the sitemap.
### `defaults` (optional)
- Default: `{}`
@@ -20,6 +20,7 @@ module.exports = function module (moduleOptions) {
cacheTime: 1000 * 60 * 15,
filter: undefined,
gzip: false,
xslUrl: undefined,
defaults: {}
}

@@ -166,6 +167,9 @@ function createSitemap (options, routes, req) {
// Set cacheTime
sitemapConfig.cacheTime = options.cacheTime || 0

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

// Create promisified instance and return
const sitemap = sm.createSitemap(sitemapConfig)
sitemap.toXML = promisify(sitemap.toXML)
@@ -20,6 +20,7 @@ module.exports = {
],
filter: ({ routes }) =>
routes.filter(route => route.url !== '/filtered'),
xslUrl: 'sitemap.xsl',
defaults: {
changefreq: 'daily',
priority: 1
@@ -83,6 +83,9 @@ describe('ssr', () => {
// filtered routes
expect(xml).not.toContain('<loc>http://localhost:3000/filtered</loc>')

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

// default options
expect(xml).toContain('<url><loc>http://localhost:3000/</loc><changefreq>daily</changefreq><priority>1.0</priority></url>')
})

0 comments on commit de1b706

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