@nuxtjs/sitemap
Advanced tools
Comparing version 0.0.5 to 0.1.0
@@ -5,2 +5,17 @@ # Change Log | ||
<a name="0.1.0"></a> | ||
# [0.1.0](https://github.com/nuxt-community/sitemap-module/compare/v0.0.5...v0.1.0) (2018-04-16) | ||
### Features | ||
* feat: add gzip compression to sitemap by default ([6cee9bd](https://github.com/nuxt-community/sitemap-module/commit/6cee9bd)), closes [#16](https://github.com/nuxt-community/sitemap-module/issues/16) | ||
### Performance Improvements | ||
* optimize lodash imports ([5e1e68f](https://github.com/nuxt-community/sitemap-module/commit/5e1e68f)) | ||
<a name="0.0.5"></a> | ||
@@ -7,0 +22,0 @@ ## [0.0.5](https://github.com/nuxt-community/sitemap-module/compare/v0.0.4...v0.0.5) (2018-04-14) |
{ | ||
"name": "@nuxtjs/sitemap", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "Automatically generate or serve dynamic sitemap.xml for Nuxt.js projects", | ||
@@ -19,2 +19,6 @@ "license": "MIT", | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0", | ||
"npm": ">=5.0.0" | ||
}, | ||
"scripts": { | ||
@@ -39,7 +43,5 @@ "dev": "nuxt test/fixture", | ||
"minimatch": "^3.0.4", | ||
"pify": "^3.0.0", | ||
"sitemap": "^1.13.0" | ||
}, | ||
"devDependencies": { | ||
"nuxt": "latest", | ||
"codecov": "latest", | ||
@@ -56,4 +58,5 @@ "eslint": "latest", | ||
"jsdom": "latest", | ||
"nuxt": "latest", | ||
"standard-version": "latest" | ||
} | ||
} |
@@ -29,2 +29,3 @@ # Sitemap Module | ||
cacheTime: 1000 * 60 * 15, | ||
gzip: true, | ||
generate: false, // Enable me when using nuxt generate | ||
@@ -81,2 +82,7 @@ exclude: [ | ||
### `gzip` | ||
- Default: `true` | ||
Enable the creation of the `.xml.gz` sitemap compressed with gzip. | ||
## Routes | ||
@@ -83,0 +89,0 @@ |
const { Minimatch } = require('minimatch') | ||
const sm = require('sitemap') | ||
const isHTTPS = require('is-https') | ||
const { unionBy, uniq } = require('lodash') | ||
const unionBy = require('lodash/unionBy') | ||
const uniq = require('lodash/uniq') | ||
const path = require('path') | ||
const fs = require('fs-extra') | ||
const AsyncCache = require('async-cache') | ||
const pify = require('pify') | ||
const { promisify } = require('util') | ||
const { hostname } = require('os') | ||
@@ -18,3 +19,4 @@ | ||
routes: [], | ||
cacheTime: 1000 * 60 * 15 | ||
cacheTime: 1000 * 60 * 15, | ||
gzip: true | ||
} | ||
@@ -31,4 +33,8 @@ | ||
options.pathGzip = (options.gzip) ? `${options.path}.gz` : options.path | ||
const gzipGeneratePath = path.resolve(this.options.srcDir, path.join('static', options.pathGzip)) | ||
// Ensure no generated file exists | ||
fs.removeSync(xmlGeneratePath) | ||
fs.removeSync(gzipGeneratePath) | ||
@@ -79,3 +85,8 @@ let staticRoutes = fs.readJsonSync(jsonStaticRoutesPath, { throws: false }) | ||
const xml = await sitemap.toXML() | ||
await fs.ensureFile(xmlGeneratePath) | ||
await fs.writeFile(xmlGeneratePath, xml) | ||
if (options.gzip) { | ||
const gzip = await sitemap.toGzip() | ||
await fs.writeFile(gzipGeneratePath, gzip) | ||
} | ||
})() | ||
@@ -86,3 +97,21 @@ } | ||
// Add server middleware | ||
if (options.gzip) { | ||
// Add server middleware for sitemap.xml.gz | ||
this.addServerMiddleware({ | ||
path: options.pathGzip, | ||
handler (req, res, next) { | ||
cache.get('routes') | ||
.then(routes => createSitemap(options, routes, req)) | ||
.then(sitemap => sitemap.toGzip()) | ||
.then(gzip => { | ||
res.setHeader('Content-Type', 'gzip') | ||
res.end(gzip) | ||
}).catch(err => { | ||
next(err) | ||
}) | ||
} | ||
}) | ||
} | ||
// Add server middleware for sitemap.xml | ||
this.addServerMiddleware({ | ||
@@ -119,3 +148,3 @@ path: options.path, | ||
}) | ||
cache.get = pify(cache.get) | ||
cache.get = promisify(cache.get) | ||
@@ -141,3 +170,3 @@ return cache | ||
const sitemap = sm.createSitemap(sitemapConfig) | ||
sitemap.toXML = pify(sitemap.toXML) | ||
sitemap.toXML = promisify(sitemap.toXML) | ||
@@ -144,0 +173,0 @@ return sitemap |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
19096
6
180
156
0
- Removedpify@^3.0.0
- Removedpify@3.0.0(transitive)