Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

metalsmith-prefix

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metalsmith-prefix

A metalsmith plugin to prefix internal URLs

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

metalsmith-prefix

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="http://example.com"></a>
<a href="path/to/url"></a>
<a href="/path/to/url"></a>

Would become this when prefixed with 'prefix'

<a href="http://example.com"></a>
<a href="path/to/url"></a>
<a href="/prefix/path/to/url"></a>

Installation

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.

CLI Usage

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"
  	}
  }
}

Javascript Usage

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'
}))

Options

You can pass options to metalsmith-prefix with the Javascript API or CLI. The options are:

  • prefix: url prefix
  • selector: css element selector

prefix

The prefix used to rewrite urls.

selector

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

License

MIT

Keywords

FAQs

Package last updated on 10 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc