1111
1212## About
1313
14- This is a PostHTML plugin that allows you to add parameters to URLs.
14+ This is a PostHTML plugin that allows you to add query string parameters to URLs.
1515
1616## Install
1717
@@ -22,18 +22,18 @@ npm i posthtml posthtml-url-parameters
2222## Usage
2323
2424``` js
25- const posthtml = require ( ' posthtml' )
26- const urlParams = require ( ' posthtml-url-parameters' )
25+ import posthtml from ' posthtml'
26+ import urlParams from ' posthtml-url-parameters'
2727
2828posthtml ([
29- urlParams ({
30- parameters: { foo: ' bar' , baz: ' qux' }
31- })
32- ])
29+ urlParams ({
30+ parameters: { foo: ' bar' , baz: ' qux' }
31+ })
32+ ])
3333 .process (' <a href="https://example.com">Test</div>' )
3434 .then (result => console .log (result .html )))
3535
36- // <a href="https://example.com?baz=qux&foo=bar">Test</div>
36+ // <a href="https://example.com?baz=qux&foo=bar">Test</div>
3737```
3838
3939## Configuration
@@ -47,12 +47,19 @@ Object containing parameter name (key) and its value.
4747Example:
4848
4949``` js
50- require (' posthtml-url-parameters' )({
51- parameters: {
52- utm_source: ' Campaign' ,
53- ' 1stDraft' : true
54- }
55- })
50+ import posthtml from ' posthtml'
51+ import urlParams from ' posthtml-url-parameters'
52+
53+ posthtml ([
54+ urlParams ({
55+ parameters: {
56+ utm_source: ' Campaign' ,
57+ ' 1stDraft' : true
58+ }
59+ })
60+ ])
61+ .process (' <a href="https://example.com">Test</a>' )
62+ .then (result => console .log (result .html ))
5663```
5764
5865### ` tags `
@@ -66,19 +73,30 @@ By default, only URLs inside [known attributes](#attributes) of tags in this arr
6673Example:
6774
6875``` js
69- require (' posthtml-url-parameters' )({
70- tags: [' a' , ' link' ],
71- // ...
72- })
76+ import posthtml from ' posthtml'
77+ import urlParams from ' posthtml-url-parameters'
78+
79+ posthtml ([
80+ urlParams ({
81+ tags: [' a' , ' img' ]
82+ })
83+ ])
84+ .process (`
85+ <a href="https://example.com">Test</a>
86+ <img src="https://example.com/image.jpg">
87+ ` )
88+ .then (result => console .log (result .html ))
7389```
7490
7591You may use some CSS selectors when specifying tags:
7692
7793``` js
78- require (' posthtml-url-parameters' )({
79- tags: [' a.button' , ' a[href*="example.com"]' ' link' ],
80- // ...
81- })
94+ posthtml ([
95+ urlParams ({
96+ tags: [' a.button' , ' a[href*="example.com"]' ' link' ],
97+ })
98+ ])
99+ .process (/* ...*/ )
82100```
83101
84102All [ ` posthtml-match-helper ` selectors] ( https://github.com/posthtml/posthtml-match-helper ) are supported.
@@ -114,8 +132,8 @@ By default, the plugin will append query parameters only to valid URLs.
114132You may disable ` strict ` mode to append parameters to any string:
115133
116134``` js
117- const posthtml = require ( ' posthtml' )
118- const urlParams = require ( ' posthtml-url-parameters' )
135+ import posthtml from ' posthtml'
136+ import urlParams from ' posthtml-url-parameters'
119137
120138posthtml ([
121139 urlParams ({
@@ -138,8 +156,8 @@ Options to pass to `query-string` - see available options [here](https://github.
138156For example, you may disable encoding:
139157
140158``` js
141- const posthtml = require ( ' posthtml' )
142- const urlParams = require ( ' posthtml-url-parameters' )
159+ import posthtml from ' posthtml'
160+ import urlParams from ' posthtml-url-parameters'
143161
144162posthtml ([
145163 urlParams ({
@@ -152,7 +170,7 @@ posthtml([
152170 .process (' <a href="https://example.com">Test</a>' )
153171 .then (result => console .log (result .html )))
154172
155- // <a href="https://example.com?foo=@Bar@">Test</a>
173+ // <a href="https://example.com?foo=@Bar@">Test</a>
156174```
157175
158176[ npm ] : https://www.npmjs.com/package/posthtml-url-parameters
@@ -161,5 +179,5 @@ posthtml([
161179[ npm-stats-shield ] : https://img.shields.io/npm/dt/posthtml-url-parameters.svg
162180[ github-ci ] : https://github.com/posthtml/posthtml-url-parameters/actions
163181[ github-ci-shield ] : https://github.com/posthtml/posthtml-url-parameters/actions/workflows/nodejs.yml/badge.svg
164- [ license ] : ./license
182+ [ license ] : ./LICENSE
165183[ license-shield ] : https://img.shields.io/npm/l/posthtml-url-parameters.svg
0 commit comments