Skip to content

Commit 4eaec8a

Browse files
committed
Ignore node_modules folder in theme folder. Resolve #1316
1 parent 9e1a92e commit 4eaec8a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/theme/processors/source.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
var Pattern = require('hexo-util').Pattern;
44
var common = require('../../plugins/processor/common');
55

6+
function startsWith(str, prefix){
7+
return str.substring(0, prefix.length) === prefix;
8+
}
9+
610
exports.process = function(file) {
711
var Asset = this.model('Asset');
812
var id = file.source.substring(this.base_dir.length).replace(/\\/g, '/');
@@ -27,10 +31,10 @@ exports.process = function(file) {
2731
};
2832

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

3236
path = path.substring(7);
33-
if (common.isHiddenFile(path) || common.isTmpFile(path)) return false;
37+
if (common.isHiddenFile(path) || common.isTmpFile(path) || ~path.indexOf('node_modules')) return false;
3438

3539
return {path: path};
3640
});

test/scripts/theme_processors/source.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ describe('source', function() {
4646
pattern.match('source/foo.jpg%').should.be.false;
4747
pattern.match('layout/foo.swig').should.be.false;
4848
pattern.match('package.json').should.be.false;
49+
pattern.match('node_modules/test/test.js').should.be.false;
50+
pattern.match('source/node_modules/test/test.js').should.be.false;
4951
});
5052

5153
it('type: create', function() {

0 commit comments

Comments
 (0)