diff --git a/lib/theme/processors/source.js b/lib/theme/processors/source.js index 9bdf509449..a306686f8f 100644 --- a/lib/theme/processors/source.js +++ b/lib/theme/processors/source.js @@ -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, '/'); @@ -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}; }); diff --git a/test/scripts/theme_processors/source.js b/test/scripts/theme_processors/source.js index 05d4af45ce..5924a61733 100644 --- a/test/scripts/theme_processors/source.js +++ b/test/scripts/theme_processors/source.js @@ -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() {