posthtml-path-prefix
Adds a prefix to all the paths for when the site is not hosted at the root of its domain
Last updated 5 months ago by silvenon .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install posthtml-path-prefix 
SYNC missed versions from official npm registry.

posthtml-path-prefix

Adds prefix to all paths in your HTML that are starting from root, which is useful when your site is not hosted at the root.

Add this plugin to your posthtml.config.js and configure the root directory where your site will be hosted at:

const pathPrefix = require('posthtml-path-prefix')

module.exports = () => {
  return {
    plugins: [
      pathPrefix({ root: '/my-site' })
    ]
  }
}

Now process some HTML:

const posthtml = require('posthtml')

const result = posthtml().process(`
  <script defer src="/script.js"></script>
  <link rel="stylesheet" href="/style.css">
  <a href="/">Home</a>
`, { sync: true })

console.log(result)

The above will log the following HTML

<script defer src="/my-site/script.js"></script>
<link rel="stylesheet" href="/my-site/style.css">
<a href="/my-site">Home</a>

To skip prefixing for a certain element add the attribute skip-prefix:

<!-- this will stay as-is -->
<a href="/another-root" skip-prefix>Home</a>

Current Tags

  • 0.1.0                                ...           latest (5 months ago)

1 Versions

  • 0.1.0                                ...           5 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (11)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |