-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (30 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var async = require('async');
var request = require('request');
function httpRequestSuccessful(url, callback) {
callback = callback || function() {};
request(url, function(error, response, body) {
if (error)
callback(error);
else if (response.statusCode != 200)
callback(Error("URL " + url + " gave status code " + response.statusCode));
else
callback();
});
}
module.exports = {
submitSitemap: function(sitemapUrl, callback) {
callback = callback || function() {};
httpRequestSuccessful(sitemapUrl, function(err) {
if (err) {
callback(err);
return;
}
var sitemapUrlParam = encodeURIComponent(sitemapUrl);
var googleSubmitUrl = "http://www.google.com/ping?sitemap=" + sitemapUrlParam;
var bingAndYahooSubmitUrl = "http://www.bing.com/ping?sitemap=" + sitemapUrlParam;
async.each([googleSubmitUrl, bingAndYahooSubmitUrl], function(url, callback) {
httpRequestSuccessful(url, callback);
}, callback);
});
}
};