Skip to content

Commit

Permalink
Ignore node_modules folder in theme folder. Resolve #1316
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy351 committed Dec 6, 2015
1 parent 9e1a92e commit 4eaec8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/theme/processors/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
var Pattern = require('hexo-util').Pattern;
var common = require('../../plugins/processor/common');

function startsWith(str, prefix){
return str.substring(0, prefix.length) === prefix;
}

exports.process = function(file) {
var Asset = this.model('Asset');
var id = file.source.substring(this.base_dir.length).replace(/\\/g, '/');
Expand All @@ -27,10 +31,10 @@ exports.process = function(file) {
};

exports.pattern = new Pattern(function(path) {
if (path.substring(0, 7) !== 'source/') return false;
if (!startsWith(path, 'source/')) return false;

path = path.substring(7);
if (common.isHiddenFile(path) || common.isTmpFile(path)) return false;
if (common.isHiddenFile(path) || common.isTmpFile(path) || ~path.indexOf('node_modules')) return false;

return {path: path};
});
2 changes: 2 additions & 0 deletions test/scripts/theme_processors/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ describe('source', function() {
pattern.match('source/foo.jpg%').should.be.false;
pattern.match('layout/foo.swig').should.be.false;
pattern.match('package.json').should.be.false;
pattern.match('node_modules/test/test.js').should.be.false;
pattern.match('source/node_modules/test/test.js').should.be.false;
});

it('type: create', function() {
Expand Down

0 comments on commit 4eaec8a

Please sign in to comment.