Website/node_modules/metalsmith-rootpath/index.js
2015-12-03 19:57:30 -05:00

35 lines
652 B
JavaScript

'use strict';
/**
* Expose `plugin`.
*/
module.exports = plugin;
/**
* Metalsmith plugin that sets a `rootPath` variable on each file's metadata.
* This allows you to find relative paths in your templates easily.
*
* @return {Function}
*/
function plugin(){
return function(files, metalsmith, done){
Object.keys(files).forEach(function(file){
setImmediate(done);
var re = /(\/|\\)+/g;
var rootPath = "";
var a;
while ((a = re.exec(file)) !== null) {
rootPath += "../";
}
files[file].rootPath = rootPath;
});
}
}