Skip to content

Commit

Permalink
Merge pull request #7 from doingweb/windows-paths
Browse files Browse the repository at this point in the history
Normalizing path options for Windows compatibility.
  • Loading branch information
lambtron committed Nov 5, 2015
2 parents c258aaa + 009e85e commit 9e2224d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

var extname = require('path').extname;
var yaml = require('js-yaml');
var path = require('path');

/**
* Expose `plugin`.
Expand Down Expand Up @@ -33,7 +34,7 @@ function plugin(opts){
var exts = Object.keys(parsers);

for (var key in opts) {
var file = opts[key];
var file = path.normalize(opts[key]);
var ext = extname(file);
if (!~exts.indexOf(ext)) throw new Error('unsupported metadata type "' + ext + '"');
if (!files[file]) throw new Error('file "' + file + '" not found');
Expand Down
18 changes: 17 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,20 @@ describe('metalsmith-metadata', function(){
done();
});
});
});

it('should work with file paths on Windows', function(done) {
var
md = metadata({ file: 'metadata/data.yaml' }),
result = {};

md({
'metadata\\data.yaml': { contents: 'string: string' }
}, {
metadata: function () { return result; }
}, function (err) {
if (err) return done(err);
assert.deepEqual(result.file, { string: 'string' });
done();
});
});
});

0 comments on commit 9e2224d

Please sign in to comment.