1.0.3 • Published 2 years ago
posthtml-anchor-amazon-associate v1.0.3
posthtml-anchor-amazon-associate
Transform Amazon link URLs to associate link using PostHTML
Transform sample
Examples of transform
{ class: 'amazon-associate', associate_id: 'xxx-20' }
Before:
<a href="https://www.amazon.com/dp/B01GRDKGZW/" class="amazon-associate">Link</a>
<a href="https://www.amazon.com/dp/B01GRDKGZW/" class="foo amazon-associate bar">Link</a>
After:
<a href="https://www.amazon.com/dp/B01GRDKGZW/ref=nosim?tag=xxx-20">Link</a>
<a href="https://www.amazon.com/dp/B01GRDKGZW/ref=nosim?tag=xxx-20" class="foo bar">Link</a>
Examples of no transform
<a class="amazon-associate">Link</a><!-- No `href` attribute -->
<a href="/" class="amazon-associate">Link</a><!-- The `href` attribute value must be an absolute URL for this feature to work -->
<a href="https://example.com/" class="amazon-associate">Link</a><!-- URL is not an Amazon page -->
<a href="https://www.amazon.com/dp/B01GRDKGZW" class="amazon-associate">Link</a><!-- A slash is required at the end of the URL -->
<a href="https://www.amazon.com/dp/B01GRDKGZW/?tag=xxx-20" class="amazon-associate">Link</a><!-- Already tagged -->
Install
npm i -D posthtml-anchor-amazon-associate
Usage
import posthtml from 'posthtml';
import posthtmlAnchorAmazonAssociate from 'posthtml-anchor-amazon-associate';
const beforeHtml = '<!DOCTYPE html>...';
const result = posthtml([
posthtmlAnchorAmazonAssociate({
class: 'amazon-associate',
associate_id: 'xxx-20',
})
]).process(beforeHtml);
const afterHtml = result.html;