metalsmith-prefix
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -81,4 +81,12 @@ | ||
function addPrefix (str, prefix) { | ||
var url = parse(str) | ||
/** | ||
* Add prefix to URL | ||
* | ||
* @param {String} input | ||
* @param {String} prefix | ||
* @return {String} | ||
*/ | ||
function addPrefix (input, prefix) { | ||
var url = parse(input) | ||
url.pathname = '/' + prefix + url.pathname | ||
@@ -88,2 +96,9 @@ return format(url) | ||
/** | ||
* Get URL attribute to rewrite from an element | ||
* | ||
* @param {Object} el | ||
* @return {String} | ||
*/ | ||
function getAttribute (el) { | ||
@@ -95,2 +110,9 @@ return (typeof map[el.name] !== 'undefined') | ||
/** | ||
* Check if URL is absolute | ||
* | ||
* @param {String} url | ||
* @return {Boolean} | ||
*/ | ||
function isAbsolute (url) { | ||
@@ -97,0 +119,0 @@ return url.indexOf('/') === 0 && |
{ | ||
"name": "metalsmith-prefix", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A metalsmith plugin to prefix internal URLs", | ||
@@ -14,5 +14,13 @@ "main": "index.js", | ||
}, | ||
"files": [ | ||
"lib/index.js" | ||
], | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"keywords": [ | ||
"metalsmith", | ||
"url", | ||
"prefix" | ||
], | ||
"repository": { | ||
@@ -19,0 +27,0 @@ "type": "git", |
@@ -5,4 +5,18 @@ # metalsmith-prefix | ||
It rewrites all absolute internal URLs to use this prefix. So references to `http://example.com` or `path/to/url` wouldn't be rewritten, but `/path/to/url` would. | ||
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 | ||
@@ -9,0 +23,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86
4860
3
93