sitemap-generator
Advanced tools
Comparing version 8.1.1 to 8.2.0
{ | ||
"name": "sitemap-generator", | ||
"version": "8.1.1", | ||
"version": "8.2.0", | ||
"description": "Easily create XML sitemaps for your website.", | ||
@@ -26,11 +26,11 @@ "homepage": "https://github.com/lgraubner/sitemap-generator", | ||
"dependencies": { | ||
"async": "2.6.0", | ||
"async": "2.6.1", | ||
"cheerio": "1.0.0-rc.2", | ||
"cp-file": "5.0.0", | ||
"cp-file": "6.0.0", | ||
"crypto-random-string": "1.0.0", | ||
"lodash": "4.17.5", | ||
"lodash": "4.17.10", | ||
"mitt": "1.1.3", | ||
"normalize-url": "2.0.1", | ||
"normalize-url": "3.0.0", | ||
"simplecrawler": "1.1.6", | ||
"url-parse": "1.3.0" | ||
"url-parse": "1.4.0" | ||
}, | ||
@@ -48,5 +48,5 @@ "engines": { | ||
"husky": "0.14.3", | ||
"jest": "22.4.3", | ||
"lint-staged": "7.0.4", | ||
"prettier": "1.11.1" | ||
"jest": "23.0.1", | ||
"lint-staged": "7.1.2", | ||
"prettier": "1.13.2" | ||
}, | ||
@@ -53,0 +53,0 @@ "scripts": { |
@@ -76,3 +76,3 @@ # Sitemap Generator | ||
maxDepth: 0, | ||
filepath: path.join(process.cwd(), 'sitemap.xml'), | ||
filepath: './sitemap.xml', | ||
maxEntriesPerFile: 50000, | ||
@@ -95,3 +95,3 @@ stripQuerystring: true | ||
Filepath for the new sitemap. If multiple sitemaps are created "part_$index" is appended to each filename. | ||
Filepath for the new sitemap. If multiple sitemaps are created "part_$index" is appended to each filename. If you don't want to write a file at all you can pass `null` as filepath. | ||
@@ -117,3 +117,3 @@ ### httpAgent | ||
Whether to add a `<lastmod>` line to each URL in the sitemap, and fill it with today's date. | ||
Whether to add a `<lastmod>` line to each URL in the sitemap. If present the responses `Last-Modified` header will be used. Otherwise todays date is added. | ||
@@ -120,0 +120,0 @@ ### maxEntriesPerFile |
@@ -16,6 +16,2 @@ const url = require('url'); | ||
if (/sitemap\.xml$/.test(href)) { | ||
return null; | ||
} | ||
// exclude "mailto:" etc | ||
@@ -22,0 +18,0 @@ if (/^[a-z]+:(?!\/\/)/i.test(href)) { |
@@ -9,2 +9,3 @@ const fs = require('fs'); | ||
const mitt = require('mitt'); | ||
const format = require('date-fns/format'); | ||
@@ -52,4 +53,6 @@ const createCrawler = require('./createCrawler'); | ||
); | ||
const sitemapPath = path.resolve(options.filepath); | ||
// only resolve if sitemap path is truthy (a string preferably) | ||
const sitemapPath = options.filepath && path.resolve(options.filepath); | ||
// we don't care about invalid certs | ||
@@ -101,3 +104,8 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; | ||
emitter.emit('add', url); | ||
sitemap.addURL(url, depth); | ||
if (sitemapPath !== null) { | ||
// eslint-disable-next-line | ||
const lastMod = queueItem.stateData.headers['last-modified']; | ||
sitemap.addURL(url, depth, lastMod && format(lastMod, 'YYYY-MM-DD')); | ||
} | ||
} | ||
@@ -113,33 +121,41 @@ }); | ||
// move files | ||
if (sitemaps.length > 1) { | ||
// multiple sitemaps | ||
let count = 1; | ||
eachSeries( | ||
sitemaps, | ||
(tmpPath, done) => { | ||
const newPath = extendFilename(sitemapPath, `_part${count}`); | ||
if (sitemapPath !== null) { | ||
// move files | ||
if (sitemaps.length > 1) { | ||
// multiple sitemaps | ||
let count = 1; | ||
eachSeries( | ||
sitemaps, | ||
(tmpPath, done) => { | ||
const newPath = extendFilename(sitemapPath, `_part${count}`); | ||
// copy and remove tmp file | ||
cpFile(tmpPath, newPath).then(() => { | ||
fs.unlink(tmpPath, () => { | ||
done(); | ||
// copy and remove tmp file | ||
cpFile(tmpPath, newPath).then(() => { | ||
fs.unlink(tmpPath, () => { | ||
done(); | ||
}); | ||
}); | ||
}); | ||
count += 1; | ||
}, | ||
() => { | ||
const filename = path.basename(sitemapPath); | ||
fs.writeFile( | ||
sitemapPath, | ||
createSitemapIndex(parsedUrl.toString(), filename, sitemaps.length), | ||
cb | ||
); | ||
} | ||
); | ||
} else if (sitemaps.length) { | ||
cpFile(sitemaps[0], sitemapPath).then(() => { | ||
fs.unlink(sitemaps[0], cb); | ||
}); | ||
count += 1; | ||
}, | ||
() => { | ||
const filename = path.basename(sitemapPath); | ||
fs.writeFile( | ||
sitemapPath, | ||
createSitemapIndex( | ||
parsedUrl.toString(), | ||
filename, | ||
sitemaps.length | ||
), | ||
cb | ||
); | ||
} | ||
); | ||
} else if (sitemaps.length) { | ||
cpFile(sitemaps[0], sitemapPath).then(() => { | ||
fs.unlink(sitemaps[0], cb); | ||
}); | ||
} else { | ||
cb(); | ||
} | ||
} else { | ||
@@ -146,0 +162,0 @@ cb(); |
@@ -6,3 +6,3 @@ const SitemapStream = require('./SitemapStream'); | ||
maxEntries, | ||
lastMod, | ||
lastModEnabled, | ||
changeFreq, | ||
@@ -14,3 +14,2 @@ priorityMap | ||
let current = null; | ||
const currentDateTime = lastMod ? getCurrentDateTime() : ''; | ||
@@ -25,3 +24,10 @@ // return temp sitemap paths | ||
// adds url to stream | ||
const addURL = (url, depth) => { | ||
const addURL = (url, depth, lastMod = getCurrentDateTime()) => { | ||
const currentDateTime = lastModEnabled ? lastMod : null; | ||
// exclude existing sitemap.xml | ||
if (/sitemap\.xml$/.test(url)) { | ||
return; | ||
} | ||
// create stream if none exists | ||
@@ -66,4 +72,4 @@ if (current === null) { | ||
addURL, | ||
finish, | ||
finish | ||
}; | ||
}; |
21006
411
+ Addedasync@2.6.1(transitive)
+ Addedcp-file@6.0.0(transitive)
+ Addedlodash@4.17.10(transitive)
+ Addednormalize-url@3.0.0(transitive)
+ Addedquerystringify@2.2.0(transitive)
+ Addedurl-parse@1.4.0(transitive)
- Removedasync@2.6.0(transitive)
- Removedcp-file@5.0.0(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removedis-plain-obj@1.1.0(transitive)
- Removedlodash@4.17.5(transitive)
- Removednormalize-url@2.0.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedprepend-http@2.0.0(transitive)
- Removedquery-string@5.1.1(transitive)
- Removedquerystringify@1.0.0(transitive)
- Removedsort-keys@2.0.0(transitive)
- Removedstrict-uri-encode@1.1.0(transitive)
- Removedurl-parse@1.3.0(transitive)
Updatedasync@2.6.1
Updatedcp-file@6.0.0
Updatedlodash@4.17.10
Updatednormalize-url@3.0.0
Updatedurl-parse@1.4.0