Skip to content
Permalink
Browse files

chore: update dependency sitemap.js to v4

BREAKING CHANGE: lastmod option parses all ISO8601 date-only strings as being in UTC rather than local time (see [sitemap.js v4 CHANGELOG]https://github.com/ekalinin/sitemap.js/blob/master/CHANGELOG.md#400))
  • Loading branch information...
NicoPennec committed Sep 26, 2019
1 parent e78e4a2 commit 795aa1ab7fe615fa0f68f4ab6384fccc791b1886
Showing with 639 additions and 590 deletions.
  1. +1 −1 README.md
  2. +3 −7 lib/builder.js
  3. +2 −4 lib/generator.js
  4. +2 −4 lib/middleware.js
  5. +1 −1 package.json
  6. +1 −11 test/__snapshots__/module.test.js.snap
  7. +629 −562 yarn.lock
@@ -74,7 +74,7 @@ You can set a single item of [sitemap](#sitemap-configuration) or [sitemap index
url: '/page/2',
changefreq: 'daily',
priority: 1,
lastmodISO: '2017-06-30T13:30:00.000Z'
lastmod: '2017-06-30T13:30:00.000Z'
}
]
}
@@ -1,6 +1,5 @@
const { hostname } = require('os')
const { URL } = require('url')
const { promisify } = require('util')

const isHTTPS = require('is-https')
const sm = require('sitemap')
@@ -11,7 +10,7 @@ const sm = require('sitemap')
* @param {Object} options
* @param {Array} routes
* @param {Request} req
* @returns {Sitemap} sitemap builder
* @returns {Sitemap} sitemap instance
*/
function createSitemap(options, routes, req = null) {
const sitemapConfig = {}
@@ -50,11 +49,8 @@ function createSitemap(options, routes, req = null) {
// Set urls and ensure they are unique
sitemapConfig.urls = [...new Set(routes)]

// Create promisified instance and return
const sitemap = sm.createSitemap(sitemapConfig)
sitemap.toXML = promisify(sitemap.toXML)

return sitemap
// Create sitemap instance
return sm.createSitemap(sitemapConfig)
}

/**
@@ -47,16 +47,14 @@ async function generateSitemap(options, globalCache, nuxtInstance) {
// Generate sitemap.xml
const routes = await cache.routes.get('routes')
const sitemap = await createSitemap(options, routes)
const xml = await sitemap.toXML()
const xmlFilePath = path.join(nuxtInstance.options.generate.dir, options.path)
fs.outputFileSync(xmlFilePath, xml)
fs.outputFileSync(xmlFilePath, sitemap.toXML())
consola.success('Generated', getPathname(nuxtInstance.options.generate.dir, xmlFilePath))

// Generate sitemap.xml.gz
if (options.gzip) {
const gzip = await sitemap.toGzip()
const gzipFilePath = path.join(nuxtInstance.options.generate.dir, options.pathGzip)
fs.outputFileSync(gzipFilePath, gzip)
fs.outputFileSync(gzipFilePath, sitemap.toGzip())
consola.success('Generated', getPathname(nuxtInstance.options.generate.dir, gzipFilePath))
}
}
@@ -63,8 +63,7 @@ function registerSitemap(options, globalCache, nuxtInstance) {
handler(req, res, next) {
cache.routes
.get('routes')
.then(routes => createSitemap(options, routes, req))
.then(sitemap => sitemap.toGzip())
.then(routes => createSitemap(options, routes, req).toGzip())
.then(gzip => {
res.setHeader('Content-Type', 'application/x-gzip')
res.setHeader('Content-Encoding', 'gzip')
@@ -84,8 +83,7 @@ function registerSitemap(options, globalCache, nuxtInstance) {
handler(req, res, next) {
cache.routes
.get('routes')
.then(routes => createSitemap(options, routes, req))
.then(sitemap => sitemap.toXML())
.then(routes => createSitemap(options, routes, req).toXML())
.then(xml => {
res.setHeader('Content-Type', 'application/xml')
res.end(xml)
@@ -55,7 +55,7 @@
"is-https": "^1.0.0",
"lodash.unionby": "^4.8.0",
"minimatch": "^3.0.4",
"sitemap": "^2.2.0"
"sitemap": "^4.1.1"
},
"devDependencies": {
"@commitlint/cli": "latest",
@@ -12,14 +12,4 @@ exports[`sitemapindex - generate mode sitemap-bar.xml 1`] = `"<?xml version=\\"1

exports[`sitemapindex - generate mode sitemap-foo.xml 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:news=\\"http://www.google.com/schemas/sitemap-news/0.9\\" xmlns:xhtml=\\"http://www.w3.org/1999/xhtml\\" xmlns:mobile=\\"http://www.google.com/schemas/sitemap-mobile/1.0\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\" xmlns:video=\\"http://www.google.com/schemas/sitemap-video/1.1\\"><url><loc>https://example.com/foo/1</loc></url><url><loc>https://example.com/foo/2</loc></url><url><loc>https://example.com/child</loc></url><url><loc>https://example.com/exclude</loc></url><url><loc>https://example.com/filtered</loc></url><url><loc>https://example.com/parent/child/subchild</loc></url><url><loc>https://example.com/parent/child</loc></url><url><loc>https://example.com/parent</loc></url><url><loc>https://example.com/sub</loc></url><url><loc>https://example.com/sub/sub</loc></url><url><loc>https://example.com/</loc></url></urlset>"`;

exports[`sitemapindex - generate mode sitemapindex.xml 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<sitemapindex xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:mobile=\\"http://www.google.com/schemas/sitemap-mobile/1.0\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\" xmlns:video=\\"http://www.google.com/schemas/sitemap-video/1.1\\">
<sitemap>
<loc>https://example.com/sitemap-foo.xml</loc>
</sitemap>
<sitemap>
<loc>https://example.fr/sitemap-bar.xml</loc>
</sitemap>
</sitemapindex>"
`;
exports[`sitemapindex - generate mode sitemapindex.xml 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><sitemapindex xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\"><sitemap><loc>https://example.com/sitemap-foo.xml</loc></sitemap><sitemap><loc>https://example.fr/sitemap-bar.xml</loc></sitemap></sitemapindex>"`;

0 comments on commit 795aa1a

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