Skip to content

Commit 99cbb53

Browse files
author
Alexander Krasnoyarov
committed
Chore: prepare 4.0.1 release.
1 parent 38eeea4 commit 99cbb53

File tree

4 files changed

+70
-38
lines changed

4 files changed

+70
-38
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Head
1+
# 4.0.1 - 2016-10-27
22

33
- Chore: added support `nodejs` `7`.
44
- Chore: update a minimal version of `npm-run-all` from `2.3.0` to `3.0.0`.
@@ -11,6 +11,7 @@
1111
- Chore: update a minimal version of `eslint-plugin-promise` from `2.0.0` to `3.0.0`.
1212
- Chore: update a minimal version of `eslint-plugin-lodash` fro `1.10.0` to `2.1.0`.
1313
- Chore: update a minimal version of `eslint-plugin-import` from `1.14.0` to `2.0.0`.
14+
- Documentation: improve `README.md` and fix typos.
1415

1516
# 4.0.0
1617

README.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,35 @@ npm install generate-robotstxt
2222
```js
2323
const robotstxt = require('generate-robotstxt').default;
2424

25-
// Pass in the absolute path to your robots.txt file
25+
robotstxt({
26+
policy: [
27+
{
28+
userAgent: 'Googlebot',
29+
allow: '/',
30+
disallow: '/search',
31+
crawlDelay: 2
32+
},
33+
{
34+
userAgent: '*',
35+
allow: '/',
36+
disallow: '/search',
37+
crawlDelay: 10,
38+
cleanParam: 'ref /articles/'
39+
}
40+
],
41+
sitemap: 'sitemap.xml',
42+
host: 'http://example.com'
43+
})
44+
.then((content) => {
45+
console.log(content);
46+
});
47+
```
48+
49+
Or
50+
51+
```js
52+
import robotstxt from 'generate-robotstxt';
53+
2654
robotstxt({
2755
policy: [
2856
{

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "generate-robotstxt",
3-
"version": "4.0.0",
3+
"version": "4.0.1",
44
"description": "Awesome generator robots.txt",
55
"author": "itgalaxy <[email protected]>",
66
"contributors": [

src/standalone.js

+38-35
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,42 @@ function addLine(name, rule) {
1616
return contents;
1717
}
1818

19+
function generatePoliceItem(item, index) {
20+
if (!item.userAgent || (item.userAgent && item.userAgent.length === 0)) {
21+
throw new Error('Each "police" should have "User-agent"');
22+
}
23+
24+
let contents = '';
25+
26+
if (index !== 0) {
27+
contents += '\n';
28+
}
29+
30+
contents += addLine('User-agent', item.userAgent);
31+
32+
if (item.allow) {
33+
contents += addLine('Allow', item.allow);
34+
}
35+
36+
if (item.disallow) {
37+
contents += addLine('Disallow', item.disallow);
38+
}
39+
40+
if (item.crawlDelay && typeof item.crawlDelay !== 'number' && !isFinite(item.crawlDelay)) {
41+
throw new Error('Options "crawlDelay" must be integer or float');
42+
}
43+
44+
if (item.crawlDelay) {
45+
contents += addLine('Crawl-delay', item.crawlDelay);
46+
}
47+
48+
if (item.cleanParam) {
49+
contents += addLine('Clean-param', item.cleanParam);
50+
}
51+
52+
return contents;
53+
}
54+
1955
export default function ({
2056
configFile = null,
2157
policy = [{
@@ -63,42 +99,9 @@ export default function ({
6399
}
64100

65101
let contents = '';
66-
let counter = 0;
67-
68-
options.policy.forEach((item) => {
69-
if (!item.userAgent || (item.userAgent && item.userAgent.length === 0)) {
70-
return reject(new Error('Each "police" should have "User-agent"'));
71-
}
72-
73-
contents += addLine('User-agent', item.userAgent);
74-
75-
if (item.allow) {
76-
contents += addLine('Allow', item.allow);
77-
}
78-
79-
if (item.disallow) {
80-
contents += addLine('Disallow', item.disallow);
81-
}
82-
83-
if (item.crawlDelay && typeof item.crawlDelay !== 'number' && !isFinite(item.crawlDelay)) {
84-
return reject(new Error('Options "crawlDelay" must be integer or float'));
85-
}
86-
87-
if (item.crawlDelay) {
88-
contents += addLine('Crawl-delay', item.crawlDelay);
89-
}
90-
91-
if (item.cleanParam) {
92-
contents += addLine('Clean-param', item.cleanParam);
93-
}
94-
95-
counter++;
96-
97-
if (counter !== options.policy.length) {
98-
contents += '\n';
99-
}
100102

101-
return item;
103+
options.policy.forEach((item, index) => {
104+
contents += generatePoliceItem(item, index);
102105
});
103106

104107
if (options.sitemap) {

0 commit comments

Comments
 (0)