-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
975f184
commit 17cbab6
Showing
7 changed files
with
204 additions
and
681 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ sitemap.fetch('https://wp.seantburke.com/sitemap.xml').then(function (sites) { | |
}); | ||
``` | ||
|
||
### Examples in ES6 | ||
### Examples | ||
|
||
```javascript | ||
import Sitemapper from 'sitemapper'; | ||
|
@@ -81,21 +81,23 @@ You can add options on the initial Sitemapper object when instantiating it. | |
- `retries`: (Number) - Sets the maximum number of retries to attempt in case of an error response (e.g. 404 or Timeout). Default: 0 | ||
- `rejectUnauthorized`: (Boolean) - If true, it will throw on invalid certificates, such as expired or self-signed ones. Default: True | ||
- `lastmod`: (Number) - Timestamp of the minimum lastmod value allowed for returned urls | ||
- `field` : (Object) - An object of fields to be returned from the sitemap. For Example: `{ loc: true, lastmod: true, changefreq: true, priority: true }`. Leaving a field out has the same effect as `field: false`. If not specified sitemapper defaults to returning the 'classic' array of urls. | ||
- `proxyAgent`: (HttpProxyAgent|HttpsProxyAgent) - instance of npm "hpagent" HttpProxyAgent or HttpsProxyAgent to be passed to npm "got" | ||
- `field` : (Object) - An object of fields to be returned from the sitemap. | ||
|
||
```javascript | ||
const sitemapper = new Sitemapper({ | ||
url: 'https://art-works.community/sitemap.xml', | ||
rejectUnauthorized: true, | ||
timeout: 15000, | ||
requestHeaders: { | ||
'User-Agent': | ||
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:81.0) Gecko/20100101 Firefox/81.0', | ||
}, | ||
}); | ||
|
||
For Example: | ||
|
||
``` | ||
{ | ||
loc: true, | ||
lastmod: true, | ||
changefreq: true, | ||
priority: true, | ||
} | ||
``` | ||
|
||
Leaving a field out has the same effect as `<field>: false`. If not specified sitemapper defaults to returning the 'classic' array of urls. | ||
|
||
An example using all available options: | ||
|
||
```javascript | ||
|
@@ -109,61 +111,13 @@ const sitemapper = new Sitemapper({ | |
debug: true, | ||
concurrency: 2, | ||
retries: 1, | ||
rejectUnauthorized: false, | ||
field: { | ||
loc: true, | ||
lastmod: true, | ||
changefreq: true, | ||
priority: true, | ||
}, | ||
proxyAgent: new HttpProxyAgent('http://localhost:8080'), | ||
}); | ||
``` | ||
|
||
### Examples in ES5 | ||
|
||
```javascript | ||
var Sitemapper = require('sitemapper'); | ||
|
||
var Google = new Sitemapper({ | ||
url: 'https://www.google.com/work/sitemap.xml', | ||
timeout: 15000, // 15 seconds | ||
}); | ||
|
||
Google.fetch() | ||
.then(function (data) { | ||
console.log(data); | ||
}) | ||
.catch(function (error) { | ||
console.log(error); | ||
}); | ||
|
||
// or | ||
|
||
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); | ||
}); | ||
``` | ||
|
||
## Version 1 | ||
|
||
```bash | ||
npm install [email protected] --save | ||
``` | ||
|
||
### Simple Example | ||
|
||
```javascript | ||
var Sitemapper = require('sitemapper'); | ||
|
||
var sitemapper = new Sitemapper(); | ||
|
||
sitemapper.getSites( | ||
'https://wp.seantburke.com/sitemap.xml', | ||
function (err, sites) { | ||
if (!err) { | ||
console.log(sites); | ||
} | ||
} | ||
); | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,47 @@ | ||
var Sitemapper = require('sitemapper'); | ||
import Sitemapper from 'sitemapper'; | ||
|
||
// Instantiate an instance with options | ||
var Google = new Sitemapper({ | ||
url: 'https://www.google.com/work/sitemap.xml', | ||
debug: false, | ||
timeout: 15000, // 15 seconds | ||
}); | ||
(async () => { | ||
const sitemapper = new Sitemapper(); | ||
|
||
// Then fetch | ||
Google.fetch() | ||
.then(function (data) { | ||
console.log(data); | ||
}) | ||
.catch(function (error) { | ||
console.log(error); | ||
const Google = new Sitemapper({ | ||
url: 'https://www.google.com/work/sitemap.xml', | ||
debug: false, | ||
timeout: 15000, // 15 seconds | ||
}); | ||
|
||
// 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) { | ||
try { | ||
const data = await Google.fetch(); | ||
console.log(data.sites); | ||
} catch (error) { | ||
console.log(error); | ||
}); | ||
} | ||
|
||
sitemapper.timeout = 5000; | ||
|
||
sitemapper | ||
.fetch('http://www.cnn.com/sitemaps/sitemap-index.xml') | ||
.then(function (data) { | ||
console.log('sites:', data.sites, 'url', data.url); | ||
}) | ||
.catch(function (error) { | ||
try { | ||
const { url, sites } = await sitemapper.fetch( | ||
'https://wp.seantburke.com/sitemap.xml' | ||
); | ||
console.log(`url:${url}`, 'sites:', sites); | ||
} catch (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) { | ||
try { | ||
const { url, sites } = await sitemapper.fetch( | ||
'http://www.cnn.com/sitemaps/sitemap-index.xml' | ||
); | ||
console.log(`url:${url}`, 'sites:', sites); | ||
} catch (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); | ||
} | ||
try { | ||
const { url, sites } = await sitemapper.fetch( | ||
'http://www.stubhub.com/new-sitemap/us/sitemap-US-en-index.xml' | ||
); | ||
console.log(`url:${url}`, 'sites:', sites); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
); | ||
})(); |
Oops, something went wrong.