@nuxtjs/sitemap
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -5,2 +5,15 @@ # Changelog | ||
## [2.1.0](https://github.com/nuxt-community/sitemap-module/compare/v2.0.1...v2.1.0) (2020-03-27) | ||
### Features | ||
* add router data to each route in the filter function ([3f58560](https://github.com/nuxt-community/sitemap-module/commit/3f58560eea2a8cf075d3265dabcf3621e02f76e6)), closes [#69](https://github.com/nuxt-community/sitemap-module/issues/69) | ||
### Bug Fixes | ||
* headers of gzipped sitemap ([938d7b6](https://github.com/nuxt-community/sitemap-module/commit/938d7b67cdacee8eb15af6b2d0adaafda08ddaa2)) | ||
* omit router data before sitemap creation ([755ec76](https://github.com/nuxt-community/sitemap-module/commit/755ec7647099c362fa18e82492cb9a790f83e46e)) | ||
### [2.0.1](https://github.com/nuxt-community/sitemap-module/compare/v2.0.0...v2.0.1) (2019-11-12) | ||
@@ -7,0 +20,0 @@ |
@@ -35,7 +35,7 @@ const { hostname } = require('os') | ||
// Set default values to each route | ||
routes = routes.map(route => ({ ...options.defaults, ...route })) | ||
routes = routes.map((route) => ({ ...options.defaults, ...route })) | ||
// Add a trailing slash to each route URL | ||
if (options.trailingSlash) { | ||
routes = routes.map(route => { | ||
routes = routes.map((route) => { | ||
if (!route.url.endsWith('/')) route.url = `${route.url}/` | ||
@@ -50,12 +50,17 @@ return route | ||
options: { ...sitemapConfig }, | ||
routes | ||
routes, | ||
}) | ||
} | ||
// Normalize to absolute path each route URL | ||
routes = routes.map(route => ({ | ||
...route, | ||
url: join('.', route.url) | ||
})) | ||
routes = routes.map((route) => { | ||
// Omit the router data | ||
const { children, chunkName, component, name, path, ...sitemapOptions } = route | ||
// Normalize to absolute path | ||
return { | ||
...sitemapOptions, | ||
url: join('.', sitemapOptions.url), | ||
} | ||
}) | ||
// Set urls and ensure they are unique | ||
@@ -81,3 +86,3 @@ sitemapConfig.urls = [...new Set(routes)] | ||
const defaultHostname = options.hostname | ||
sitemapIndexConfig.urls = options.sitemaps.map(options => { | ||
sitemapIndexConfig.urls = options.sitemaps.map((options) => { | ||
// Normalize to absolute path | ||
@@ -84,0 +89,0 @@ const path = join('.', options.gzip ? `${options.path}.gz` : options.path) |
@@ -25,3 +25,3 @@ const { promisify } = require('util') | ||
} | ||
} | ||
}, | ||
}) | ||
@@ -28,0 +28,0 @@ cache.get = promisify(cache.get) |
@@ -88,3 +88,5 @@ const path = require('path') | ||
// Generate linked sitemaps | ||
await Promise.all(options.sitemaps.map(sitemapOptions => generateSitemaps(sitemapOptions, globalCache, nuxtInstance))) | ||
await Promise.all( | ||
options.sitemaps.map((sitemapOptions) => generateSitemaps(sitemapOptions, globalCache, nuxtInstance)) | ||
) | ||
} | ||
@@ -91,0 +93,0 @@ |
@@ -8,3 +8,3 @@ /* istanbul ignore file */ | ||
message: `[sitemap-module] ${message}`, | ||
additional: JSON.stringify(options, null, 2) | ||
additional: JSON.stringify(options, null, 2), | ||
}) | ||
@@ -16,3 +16,3 @@ } | ||
message: `[sitemap-module] ${message}`, | ||
additional: options ? JSON.stringify(options, null, 2) : null | ||
additional: options ? JSON.stringify(options, null, 2) : null, | ||
}) | ||
@@ -19,0 +19,0 @@ } |
@@ -70,4 +70,3 @@ const { gzipSync } = require('zlib') | ||
// Send http response | ||
res.setHeader('Content-Type', 'application/x-gzip') | ||
res.setHeader('Content-Encoding', 'gzip') | ||
res.setHeader('Content-Type', 'application/gzip') | ||
res.end(gzip) | ||
@@ -78,3 +77,3 @@ } catch (err) { | ||
} | ||
} | ||
}, | ||
}) | ||
@@ -103,3 +102,3 @@ } | ||
} | ||
} | ||
}, | ||
}) | ||
@@ -129,6 +128,5 @@ } | ||
const gzip = gzipSync(sitemapIndex) | ||
res.setHeader('Content-Type', 'application/x-gzip') | ||
res.setHeader('Content-Encoding', 'gzip') | ||
res.setHeader('Content-Type', 'application/gzip') | ||
res.end(gzip) | ||
} | ||
}, | ||
}) | ||
@@ -144,9 +142,9 @@ } | ||
res.end(sitemapIndex) | ||
} | ||
}, | ||
}) | ||
// Register linked sitemaps | ||
options.sitemaps.forEach(sitemapOptions => registerSitemaps(sitemapOptions, globalCache, nuxtInstance, depth + 1)) | ||
options.sitemaps.forEach((sitemapOptions) => registerSitemaps(sitemapOptions, globalCache, nuxtInstance, depth + 1)) | ||
} | ||
module.exports = { registerSitemaps, registerSitemap, registerSitemapIndex } |
@@ -26,3 +26,3 @@ const path = require('path') | ||
// Init static routes | ||
nuxtInstance.extendRoutes(routes => { | ||
nuxtInstance.extendRoutes((routes) => { | ||
// Create a cache for static routes | ||
@@ -41,7 +41,7 @@ globalCache.staticRoutes = getStaticRoutes(routes) | ||
logger.info('Generating sitemaps') | ||
await Promise.all(options.map(options => generateSitemaps(options, globalCache, nuxtInstance))) | ||
await Promise.all(options.map((options) => generateSitemaps(options, globalCache, nuxtInstance))) | ||
}) | ||
// On "universal" mode, register middlewares for each sitemap or sitemapindex | ||
options.forEach(options => { | ||
options.forEach((options) => { | ||
registerSitemaps(options, globalCache, nuxtInstance) | ||
@@ -48,0 +48,0 @@ }) |
@@ -27,3 +27,3 @@ const logger = require('./logger') | ||
trailingSlash: false, | ||
defaults: {} | ||
defaults: {}, | ||
} | ||
@@ -33,3 +33,3 @@ | ||
...defaults, | ||
...options | ||
...options, | ||
} | ||
@@ -65,3 +65,3 @@ | ||
xmlNs: undefined, | ||
xslUrl: undefined | ||
xslUrl: undefined, | ||
} | ||
@@ -71,3 +71,3 @@ | ||
...defaults, | ||
...options | ||
...options, | ||
} | ||
@@ -85,3 +85,3 @@ | ||
sitemapIndexOptions.sitemaps.forEach(sitemapOptions => { | ||
sitemapIndexOptions.sitemaps.forEach((sitemapOptions) => { | ||
/* istanbul ignore if */ | ||
@@ -88,0 +88,0 @@ if (!sitemapOptions.path) { |
@@ -11,6 +11,6 @@ const { Minimatch } = require('minimatch') | ||
function excludeRoutes(patterns, routes) { | ||
patterns.forEach(pattern => { | ||
patterns.forEach((pattern) => { | ||
const minimatch = new Minimatch(pattern) | ||
minimatch.negate = true | ||
routes = routes.filter(route => minimatch.match(route)) | ||
routes = routes.filter(({ url }) => minimatch.match(url)) | ||
}) | ||
@@ -28,3 +28,3 @@ return routes | ||
// Get all static routes and ignore dynamic routes | ||
return flattenRoutes(router).filter(route => !route.includes(':') && !route.includes('*')) | ||
return flattenRoutes(router).filter(({ url }) => !url.includes(':') && !url.includes('*')) | ||
} | ||
@@ -41,3 +41,3 @@ | ||
function flattenRoutes(router, path = '', routes = []) { | ||
router.forEach(route => { | ||
router.forEach((route) => { | ||
if (route.children) { | ||
@@ -47,3 +47,6 @@ flattenRoutes(route.children, path + route.path + '/', routes) | ||
if (route.path !== '') { | ||
routes.push(path + route.path) | ||
routes.push({ | ||
...route, | ||
url: path + route.path, | ||
}) | ||
} | ||
@@ -50,0 +53,0 @@ }) |
{ | ||
"name": "@nuxtjs/sitemap", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Automatically generate or serve dynamic sitemap.xml for Nuxt.js projects", | ||
@@ -47,4 +47,3 @@ "keywords": [ | ||
"*.{js,vue}": [ | ||
"eslint --fix", | ||
"git add" | ||
"eslint --fix" | ||
] | ||
@@ -54,3 +53,3 @@ }, | ||
"async-cache": "^1.1.0", | ||
"consola": "^2.11.0", | ||
"consola": "^2.11.3", | ||
"fs-extra": "^8.1.0", | ||
@@ -57,0 +56,0 @@ "is-https": "^1.0.0", |
40505
588
Updatedconsola@^2.11.3