forked from seantomburke/sitemapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
56 lines (48 loc) · 1.26 KB
/
example.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var Sitemapper = require('sitemapper');
// Instantiate an instance with options
var Google = new Sitemapper({
url: 'https://www.google.com/work/sitemap.xml',
debug: false,
timeout: 15000 //15 seconds
});
// Then fetch
Google.fetch()
.then(function (data) {
console.log(data);
})
.catch(function (error) {
console.log(error);
});
// Instantiate an instance with no options
var sitemapper = new Sitemapper();
sitemapper.timeout = 5000;
sitemapper.fetch('https://wp.seantburke.com/sitemap.xml')
.then(function (data) {
console.log(data);
})
.catch(function (error) {
console.log(error);
});
sitemapper.fetch('http://www.cnn.com/sitemaps/sitemap-index.xml')
.then(function (data) {
console.log('sites:', data.sites, 'url', data.url);
})
.catch(function (error) {
console.log(error);
});
sitemapper.fetch('http://www.stubhub.com/new-sitemap/us/sitemap-US-en-index.xml')
.then(function (data) {
console.log('sites:', data.sites, 'url', data.url);
})
.catch(function (error) {
console.log(error);
});
// Version 1.0.0 example which has been deprecated.
sitemapper.getSites('https://wp.seantburke.com/sitemap.xml', function (err, sites) {
if (!err) {
console.log(sites);
}
else {
console.log(err);
}
});