Skip to content

Commit

Permalink
Fixes "too many opened files" error (#120)
Browse files Browse the repository at this point in the history
* Fixes a problem with too many opened files when treating a large number of input files.

* Tab to space.
  • Loading branch information
bbor authored and ismay committed Apr 20, 2017
1 parent d63d951 commit aee9acd
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function plugin(opts){
return function(files, metalsmith, done){
var metadata = metalsmith.metadata();
var matches = {};
var templates = {};

/**
* Process any partials and pass them to consolidate as a partials object
Expand All @@ -114,7 +115,13 @@ function plugin(opts){
debug('stringifying file: %s', file);
var data = files[file];
data.contents = data.contents.toString();
matches[file] = data;
var template = metalsmith.path(dir, data.layout || def);
if (!templates[template]) {
debug('found new template: %s', template);
templates[template] = file;
} else {
matches[file] = data;
}
});

/**
Expand Down Expand Up @@ -153,8 +160,17 @@ function plugin(opts){
}

/**
* Render all matched files
* Render all matched files.
*/
each(Object.keys(matches), convert, done);
function renderFiles(err) {
if (err) {
return done(err);
}
each(Object.keys(matches), convert, done);
}

// Do a first pass to load templates into the consolidate cache.
each(templates, convert, renderFiles);

};
}

0 comments on commit aee9acd

Please sign in to comment.