Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #175 from hcodes/sitemap2
Browse files Browse the repository at this point in the history
v7.2.0
  • Loading branch information
hcodes committed Oct 10, 2021
2 parents 2f284b3 + 7a5dae1 commit 86a27b6
Show file tree
Hide file tree
Showing 5 changed files with 424 additions and 439 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v7.2.0
- Update deps in package.json
- Fixed sitemap bug #169

## v7.1.0
Added junit report #171 @Lootjs.

Expand Down
2 changes: 1 addition & 1 deletion lib/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ async.series(
).then(() => {
reports.onComplete(mergedOptions.configRelativePath);
process.exit();
});
}).catch(() => {});
42 changes: 30 additions & 12 deletions lib/yaspeller.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function checkUrl(url, callback, settings) {
if (response.ok) {
return response.text();
} else {
throw Error(url + ': returns status code is ' + response.statusCode);
throw Error(url + ': returns status code is ' + response.status);
}
})
.then(text => {
Expand Down Expand Up @@ -282,7 +282,7 @@ function checkSitemap(url, commonCallback, settings, callback) {
if (res.ok) {
return res.text();
} else {
throw Error(url + ': returns status code is ' + res.statusCode);
throw Error(url + ': returns status code is ' + res.status);
}
})
.then(xml => {
Expand All @@ -297,17 +297,34 @@ function checkSitemap(url, commonCallback, settings, callback) {
}

const tasks = [];
if (result && result.urlset && Array.isArray(result.urlset.url)) {
result.urlset.url.forEach(function(el) {
el.loc && el.loc.forEach(function(url) {
tasks.push(function(cb) {
checkUrl(url, function(err, data, originalText) {
callback && callback(err, data, originalText);
cb(null, [err, data]);
}, settings);
if (result) {
const urlset = result.urlset;
if (urlset && Array.isArray(urlset.url)) {
urlset.url.forEach(function(el) {
el.loc && el.loc.forEach(function(url) {
tasks.push(function(cb) {
checkUrl(url, function(err, data, originalText) {
callback && callback(err, data, originalText);
cb(null, [err, data]);
}, settings);
});
});
});
});
}

const sitemapindex = result.sitemapindex;
if (sitemapindex && Array.isArray(sitemapindex.sitemap)) {
sitemapindex.sitemap.forEach(function(el) {
el.loc && el.loc.forEach(function(url) {
tasks.push(function(cb) {
checkUrl(url, function(err, data, originalText) {
callback && callback(err, data, originalText);
cb(null, [err, data]);
}, settings);
});
});
});
}
}

async.parallelLimit(tasks, getMaxRequest(settings), function(err, data) {
Expand All @@ -319,6 +336,7 @@ function checkSitemap(url, commonCallback, settings, callback) {
const obj = [true, error];
results.push(obj);
callback && callback.apply(this, obj);

commonCallback(results);
});
}
Expand Down Expand Up @@ -393,7 +411,7 @@ function removeDuplicates(data) {
if (Array.isArray(s) && s.length) {
obj[code][word].suggest = s;
}

if (hasPosition) {
obj[code][word].position = el.position;
}
Expand Down
Loading

0 comments on commit 86a27b6

Please sign in to comment.