# metalsmith-prefix

> A metalsmith plugin to prefix internal URLs

Latest version **1.0.3** (published 2015-10-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install metalsmith-prefix
pnpm add metalsmith-prefix
yarn add metalsmith-prefix
bun add metalsmith-prefix
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2015-10-10 |
| First published | 2015-10-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ross Zurowski |
| Maintainers | rosszurowski |
| Keywords | metalsmith, url, prefix |

## Links

- npm: https://www.npmjs.com/package/metalsmith-prefix
- Repository: https://github.com/rosszurowski/metalsmith-prefix
- Homepage: https://github.com/rosszurowski/metalsmith-prefix#readme
- Issues: https://github.com/rosszurowski/metalsmith-prefix/issues
- npm.io page: https://npm.io/package/metalsmith-prefix

## Dependencies (1)

- [cheerio](https://npm.io/package/cheerio.md) ^0.19.0

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2015-10-10
- 1.0.2 — 2015-10-10
- 1.0.1 — 2015-10-10
- 1.0.0 — 2015-10-10

## README

# 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](https://github.com/evoja/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

```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'

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

## Installation

```bash
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`.

```json
{
  "plugins": {
    "metalsmith-prefix": "blog"
  }
}
```

Or by passing in options

```json
{
  "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:

```javascript

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](https://github.com/segmentio/metalsmith#api) or [CLI](https://github.com/segmentio/metalsmith#cli). The options are:

* [prefix](#prefix): url prefix
* [selector](#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](https://github.com/cheeriojs/cheerio) to parse any HTML outputs for URLs and rewrites them. This option defaults to `a, link, script, img, video, audio, source`

## License

MIT

---
_Source: https://npm.io/package/metalsmith-prefix · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
