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

        });
    }
}
@@ -418,16 +418,19 @@
 e = /(%5C/
+%7C%5C%5C
 )+/g;%0A%0A 
@@ -644,8 +644,9 @@
 %0A    %7D%0A%7D
+%0A

update regex to work with windoze paths