metalsmith-metadata
Advanced tools
Comparing version
@@ -39,15 +39,17 @@ | ||
if (!~exts.indexOf(ext)) throw new Error('unsupported metadata type "' + ext + '"'); | ||
if (!files[file]) throw new Error('file "' + file + '" not found'); | ||
if (!metadata[key] || files[file]) { | ||
if (!files[file]) throw new Error('file "' + file + '" not found'); | ||
var parse = parsers[ext]; | ||
var str = files[file].contents.toString(); | ||
delete files[file]; | ||
var parse = parsers[ext]; | ||
var str = files[file].contents.toString(); | ||
delete files[file]; | ||
try { | ||
var data = parse(str); | ||
} catch (e) { | ||
return done(new Error('malformed data in "' + file + '"')); | ||
try { | ||
var data = parse(str); | ||
} catch (e) { | ||
return done(new Error('malformed data in "' + file + '"')); | ||
} | ||
metadata[key] = data; | ||
} | ||
metadata[key] = data; | ||
} | ||
@@ -54,0 +56,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"repository": "git://github.com/segmentio/metalsmith-metadata.git", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "lib/index.js", |
@@ -28,2 +28,26 @@ | ||
it('should not parse a file if the key already exists in the metadata', function(done){ | ||
var m = Metalsmith('test/fixtures/json') | ||
.use(metadata({ file: 'data.json' })) | ||
.use(metadata({ file: 'missing.json' })); | ||
m.build(function(err){ | ||
if (err) return done(err); | ||
assert.deepEqual(m.metadata().file, { string: 'string' }); | ||
assert(!exists('test/fixtures/json/build')); | ||
done(); | ||
}); | ||
}); | ||
it('should parse a file even if the key exists if the file is in the bundle', function(done){ | ||
var m = Metalsmith('test/fixtures/duplicate') | ||
.use(metadata({ file: 'data.json' })) | ||
.use(metadata({ file: 'data2.json' })); | ||
m.build(function(err){ | ||
if (err) return done(err); | ||
assert.deepEqual(m.metadata().file, { string: 'string2' }); | ||
assert(!exists('test/fixtures/json/build')); | ||
done(); | ||
}); | ||
}); | ||
it('should parse YAML', function(done){ | ||
@@ -30,0 +54,0 @@ var m = Metalsmith('test/fixtures/yaml').use(metadata({ file: 'data.yaml' })); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
4784
26.23%12
20%107
35.44%0
-100%