Skip to content

Commit

Permalink
Add basic support for redirections
Browse files Browse the repository at this point in the history
For now, it will only delete the record for redirected urls.
  • Loading branch information
nitriques committed Dec 6, 2018
1 parent 3c8316b commit a113ba2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ sitemap(config, (sitemap, urls) => {
if (!!error) {
errors.push(error);
}
if (!!error.pageNotFound && !!record) {
if ((!!error.pageNotFound || !!error.pageRedirected) && !!record) {
pages.deleteObject(record.objectID, (error, result) => {
console.log('%d - Deleted %s:%s (%s)', id, record.objectID, record.lang, record.url);

Expand Down
7 changes: 7 additions & 0 deletions lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ module.exports = (data, cb) => {
pageNotFound: true
}, record);
return;
} else if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307) {
cb({
ok: 'warn',
message: 'Page redirected ' + url.url + ' to ' + res.headers.location,
pageRedirected: true
}, record);
return;
} else if (res.statusCode !== 200) {
cb({
ok: false,
Expand Down

0 comments on commit a113ba2

Please sign in to comment.