Skip to content

Commit

Permalink
Updating Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
seantomburke committed Nov 8, 2024
1 parent 975f184 commit 17cbab6
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 681 deletions.
7 changes: 5 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Contributing

The files to modify are under the `src` folder. `src/assets` are JavaScript files written in es6 that get compiled
The files to modify are under the `src` folder. `src/assets` are JavaScript files written in JavaScript that get compiled
through babel into `lib/sitemapper.js`.

### Build
Expand All @@ -11,7 +11,7 @@ To build the `lib` directory with the compiled assets use this command
npm run build
```

This uses [Babel](http://babeljs.io/) to compile the files. Make sure to run `npm run build` before submitting a pull request.
This uses [Babel](http://babeljs.io/) to compile the files. The prepack step will run `npm run build` when submitting a pull request.

```bash
# Run examples/index.js
Expand Down Expand Up @@ -58,7 +58,10 @@ src/
assets/
sitemapper.js
examples/
google.js
index.js
tests/
test.js
test.ts.ts
tsconfig.json
```
90 changes: 22 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ sitemap.fetch('https://wp.seantburke.com/sitemap.xml').then(function (sites) {
});
```

### Examples in ES6
### Examples

```javascript
import Sitemapper from 'sitemapper';
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}
);
```
47 changes: 0 additions & 47 deletions example.es6.js

This file was deleted.

85 changes: 36 additions & 49 deletions example.js
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);
}
);
})();
Loading

0 comments on commit 17cbab6

Please sign in to comment.