Skip to content

Commit

Permalink
v2.0.0 with modify function
Browse files Browse the repository at this point in the history
  • Loading branch information
russellsteadman committed Jul 3, 2018
1 parent 470a8f8 commit d2466c8
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 44 deletions.
2 changes: 1 addition & 1 deletion dist/affiliate.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/affiliate.node.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 24 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ const aff = Affiliate({
to: 'my-tag'
}
],
modifyPath: function (path) { // a function that returns a new path
return path + '-tag';
},
modifyHost: function (host) { // a function that returns a new host
return host.split(':')[0] + '.rdr.example.com';
modify: function (url) { // a function that directly modifies the URL
url.set('pathname', url.pathname + '-tag');
url.set('hostname', url.hostname + '.rdr.example.com');
return url;
}
}
]
Expand All @@ -54,6 +53,26 @@ aff.attach();

After passing the configuration to Affiliate, it will search the DOM and automatically and change links. Then whenever the DOM is modified, it will search through the modifications and change those links for no-hassle affiliation.

#### config.log

A boolean of whether or not to enable verbose logging.

#### config.tags[].hosts

An array of the hosts to match.

#### config.tags[].query

An object to update the query of the url.

#### config.tags[].replace

An array of objects with a `from` key that is a regex or string and a `to` key that is the value that will replace the `from` key.

#### config.tags[].modify

This exposes an instance of the [`url-parse`](https://www.npmjs.com/package/url-parse#usage) library. This can be used to update individual parts of the URL, such as the hostname or hash. It expects the instance or a URL string to be returned.

## Affiliate API

```js
Expand Down
18 changes: 8 additions & 10 deletions docs/test/affiliate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ var optionOne = {
to: 'my-tag'
}
],
modifyPath: function (path) {
return path + '-tag';
},
modifyHost: function (host) {
return 'tst.' + host;
modify: function (url) {
url.set('pathname', url.pathname + '-tag');
url.set('hostname', 'tst.' + url.hostname);
return url;
}
}
]
Expand All @@ -46,11 +45,10 @@ var optionTwo = {
to: 'my-tag2'
}
],
modifyPath: function (path) {
return path + '-tag2';
},
modifyHost: function (host) {
return 'tst2.' + host;
modify: function (url) {
url.set('pathname', url.pathname + '-tag2');
url.set('hostname', 'tst2.' + url.hostname);
return url;
}
}
]
Expand Down
Loading

0 comments on commit d2466c8

Please sign in to comment.