Skip to content

Commit

Permalink
refactor: use object spread operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Pennec committed May 10, 2019
1 parent 0cf1ab1 commit a45de6f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/module.js
Expand Up @@ -24,7 +24,12 @@ module.exports = function module (moduleOptions) {
defaults: {} defaults: {}
} }


const options = Object.assign({}, defaults, this.options.sitemap, moduleOptions) const options = {
...defaults,
...this.options.sitemap,
...moduleOptions
}

options.pathGzip = options.gzip ? `${options.path}.gz` : options.path options.pathGzip = options.gzip ? `${options.path}.gz` : options.path


// sitemap-routes.json is written to dist dir on "build" mode // sitemap-routes.json is written to dist dir on "build" mode
Expand Down Expand Up @@ -155,11 +160,11 @@ function createSitemap (options, routes, req) {
sitemapConfig.hostname = options.hostname || sitemapConfig.hostname = options.hostname ||
(req && `${isHTTPS(req) ? 'https' : 'http'}://${req.headers.host}`) || `http://${hostname()}` (req && `${isHTTPS(req) ? 'https' : 'http'}://${req.headers.host}`) || `http://${hostname()}`


routes = routes.map(route => Object.assign({}, options.defaults, route)) routes = routes.map(route => ({ ...options.defaults, ...route }))


// Enable filter function for each declared route // Enable filter function for each declared route
if (typeof options.filter === 'function') { if (typeof options.filter === 'function') {
routes = options.filter({ routes, options: Object.assign({}, options, sitemapConfig) }) routes = options.filter({ routes, options: { ...options, ...sitemapConfig } })
} }


// Set urls and ensure they are unique // Set urls and ensure they are unique
Expand Down

0 comments on commit a45de6f

Please sign in to comment.