A metalsmith plugin to prefix internal URLs on your site. Helpful for deploying to nested urls (like example.com/blog) while developing locally. Written because metalsmith-prefixoid wasn't working for me.
It rewrites all absolute internal URLs to use this prefix, but no external or relative ones. So the rendered html
<a href="/path/a"></a>
<a href="/path/b/"></a>
<a href="http://example.com"></a>
<a href="path/to/url"></a>
Would become this when prefixed with prefix
<a href="/prefix/path/a"></a>
<a href="/prefix/path/b/"></a>
<a href="http://example.com"></a>
<a href="path/to/url"></a>
npm install metalsmith-prefix
Because metalsmith-prefix
parses output HTML, it should be placed near the end of your plugin chain, after all your templates have already been rendered.
Install through npm and then add the metalsmith-prefix
key to your metalsmith.json
.
{
"plugins": {
"metalsmith-prefix": "blog"
}
}
Or by passing in options
{
"plugins": {
"metalsmith-prefix": {
"prefix": "blog",
"selector": "a, img, link, script"
}
}
}
Pass options
to the plugin and pass it to Metalsmith with the use
method:
var prefix = require('metalsmith-prefix')
metalsmith.use(prefix({
prefix: 'blog',
selector: 'a, img, link, script'
}))
You can pass options to metalsmith-prefix
with the Javascript API or CLI. The options are:
The prefix used to rewrite urls.
The selector used to find elements with URLs to rewrite. Metalsmith-prefix uses cheerio to parse any HTML outputs for URLs and rewrites them. This option defaults to a, link, script, img, video, audio, source
MIT