Skip to content

Commit

Permalink
feat: Ignore files from processing
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaskarmelkani committed Jul 3, 2017
1 parent 5a28258 commit 8844a9e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 16 additions & 0 deletions lib/box/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var util = require('hexo-util');
var fs = require('hexo-fs');
var chalk = require('chalk');
var EventEmitter = require('events').EventEmitter;
var minimatch = require('minimatch');

var Pattern = util.Pattern;
var join = pathFn.join;
Expand Down Expand Up @@ -35,6 +36,11 @@ function Box(ctx, base, options) {
this.watcher = null;
this.Cache = ctx.model('Cache');
this.File = this._createFileClass();
this.ignore = ctx.config.ignore;

if (!Array.isArray(this.ignore)){
this.ignore = [this.ignore];
}
}

require('util').inherits(Box, EventEmitter);
Expand Down Expand Up @@ -107,9 +113,19 @@ Box.prototype._readDir = function(base, fn, prefix) {
prefix = prefix || '';

var self = this;
var ignore = self.ignore;

if(base && ignore && ignore.length){
for (var i = 0, len = ignore.length; i < len; i++) {
if (minimatch(base, ignore[i])){
return Promise.resolve("Ignoring dir.");
}
}
}

return fs.readdir(base).map(function(path) {
return fs.stat(join(base, path)).then(function(stats) {

if (stats.isDirectory()) {
return self._readDir(join(base, path), fn, prefix + path + '/');
}
Expand Down
7 changes: 5 additions & 2 deletions lib/hexo/default_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@ module.exports = {
// Extensions
theme: 'landscape',
// Deployment
deploy: {}
};
deploy: {},

//ignore files from processing
ignore: []
};

0 comments on commit 8844a9e

Please sign in to comment.