posthtml-url-parameters
PostHTML plugin for adding parameters to URLs.
Last updated 2 months ago by cossssmin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install posthtml-url-parameters 
SYNC missed versions from official npm registry.

URL Parameters

Add parameters to URLs

Version License Build Downloads

About

This is a PostHTML plugin that allows you to add parameters to URLs.

Install

$ npm i posthtml posthtml-url-parameters

Usage

const posthtml = require('posthtml')
const urlParams = require('posthtml-url-parameters')

posthtml([
    urlParams({
      parameters: { foo: 'bar', baz: 'qux' }
    })
  ])
  .process('<a href="https://example.com">Test</div>')
  .then(result => console.log(result.html)))

  // <a href="https://example.com?baz=qux&foo=bar">Test</div>

Configuration

parameters

Default: undefined

Object containing parameter name (key) and its value.

Example:

require('posthtml-url-parameters')({
  parameters: {
    utm_source: 'Campaign',
    '1stDraft': true
  }
})

tags

Default: [a]

Array of tag names to process. Only URLs inside href="" attributes of tags in this array will be processed.

Example:

require('posthtml-url-parameters')({
  tags: ['a', 'link'],
  // ...
})

qs

Default: undefined

Options to pass to query-string - see available options here.

For example, you can disable encoding:

const posthtml = require('posthtml')
const urlParams = require('posthtml-url-parameters')

posthtml([
    urlParams({
      parameters: { foo: '@Bar@' },
      qs: {
        encode: false
      }
    })
  ])
  .process('<a href="https://example.com">Test</div>')
  .then(result => console.log(result.html)))

  // <a href="https://example.com?foo=@Bar@">Test</div>

Current Tags

  • 1.0.3                                ...           latest (2 months ago)

4 Versions

  • 1.0.3                                ...           2 months ago
  • 1.0.2                                ...           4 months ago
  • 1.0.1                                ...           4 months ago
  • 1.0.0                                ...           4 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 5
Dependencies (3)
Dev Dependencies (4)

Copyright 2014 - 2017 © taobao.org |