Skip to content

Commit 2876faf

Browse files
committed
Fix backslash bug on Windows
1 parent 0bf6e43 commit 2876faf

File tree

7 files changed

+15
-20
lines changed

7 files changed

+15
-20
lines changed

lib/box/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var util = require('hexo-util');
66
var fs = require('hexo-fs');
77
var prettyHrtime = require('pretty-hrtime');
88
var crypto = require('crypto');
9-
var tildify = require('tildify');
109
var chalk = require('chalk');
1110

1211
var Pattern = util.Pattern;
@@ -212,6 +211,8 @@ Box.prototype._handleUpdatedFile = function(path){
212211
self.bufferStore[path] = data.content;
213212

214213
if (!cache){
214+
ctx.log.info('Added: %s', chalk.magenta(id));
215+
215216
return Cache.insert({
216217
_id: id,
217218
checksum: checksum
@@ -220,11 +221,15 @@ Box.prototype._handleUpdatedFile = function(path){
220221
path: path
221222
});
222223
} else if (cache.checksum === checksum){
224+
ctx.log.info('Unchanged: %s', chalk.magenta(id));
225+
223226
return {
224227
type: 'skip',
225228
path: path
226229
};
227230
} else {
231+
ctx.log.info('Updated: %s', chalk.magenta(id));
232+
228233
cache.checksum = checksum;
229234
return cache.save().thenReturn({
230235
type: 'update',
@@ -246,6 +251,7 @@ Box.prototype._handleDeletedFile = function(path){
246251
var cache = Cache.findById(id);
247252
if (!cache) return resolve();
248253

254+
ctx.log.debug('Deleted: %s', chalk.magenta(id));
249255
return cache.remove().then(resolve, reject);
250256
}).thenReturn({
251257
type: 'delete',
@@ -350,24 +356,17 @@ Box.prototype.watch = function(callback){
350356
self.watcher = watcher;
351357

352358
watcher.on('add', function(path){
353-
log.info('Added: %s', displayPath(path));
354359
self._handleUpdatedFile(getPath(path)).then(dispatch);
355360
}).on('change', function(path){
356-
log.info('Updated: %s', displayPath(path));
357361
self._handleUpdatedFile(getPath(path)).then(dispatch);
358362
}).on('unlink', function(path){
359-
log.info('Deleted: %s', displayPath(path));
360363
self._handleDeletedFile(getPath(path)).then(dispatch);
361364
});
362365

363366
return watcher;
364367
}).nodeify(callback);
365368
};
366369

367-
function displayPath(path){
368-
return chalk.magenta(tildify(path));
369-
}
370-
371370
Box.prototype.unwatch = function(){
372371
if (!this.watcher) throw new Error('Watcher hasn\'t started yet.');
373372

lib/plugins/helper/css.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
var pathFn = require('path');
2-
31
function cssHelper(){
42
var result = '';
53
var path = '';
@@ -10,7 +8,7 @@ function cssHelper(){
108
if (Array.isArray(path)){
119
result += cssHelper.apply(this, path);
1210
} else {
13-
if (pathFn.extname(path) !== '.css') path += '.css';
11+
if (path.substring(path.length - 4, path.length) !== '.css') path += '.css';
1412
result += '<link rel="stylesheet" href="' + this.url_for(path) + '" type="text/css">\n';
1513
}
1614
}

lib/plugins/helper/js.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
var pathFn = require('path');
2-
31
function jsHelper(){
42
var result = '';
53
var path = '';
@@ -10,7 +8,7 @@ function jsHelper(){
108
if (Array.isArray(path)){
119
result += jsHelper.apply(this, path);
1210
} else {
13-
if (pathFn.extname(path) !== '.js') path += '.js';
11+
if (path.substring(path.length - 3, path.length) !== '.js') path += '.js';
1412
result += '<script src="' + this.url_for(path) + '" type="text/javascript"></script>\n';
1513
}
1614
}

lib/plugins/processor/asset.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function processPage(file){
7474
}
7575

7676
function processAsset(file){
77-
var id = file.source.substring(this.base_dir.length);
77+
var id = file.source.substring(this.base_dir.length).replace(/\\/g, '/');
7878
var Asset = this.model('Asset');
7979
var doc = Asset.findById(id);
8080

lib/plugins/processor/post.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function scanAssetDir(post){
204204
}).filter(function(item){
205205
return !common.isTmpFile(item) && !common.isHiddenFile(item);
206206
}).map(function(item){
207-
var id = pathFn.join(assetDir, item).substring(baseDirLength);
207+
var id = pathFn.join(assetDir, item).substring(baseDirLength).replace(/\\/g, '/');
208208
var asset = PostAsset.findById(id);
209209
if (asset) return;
210210

@@ -220,7 +220,7 @@ function scanAssetDir(post){
220220
function processAsset(file){
221221
var PostAsset = this.model('PostAsset');
222222
var Post = this.model('Post');
223-
var id = file.source.substring(this.base_dir.length);
223+
var id = file.source.substring(this.base_dir.length).replace(/\\/g, '/');
224224
var doc = PostAsset.findById(id);
225225
var post;
226226

lib/theme/processors/source.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var common = require('../../plugins/processor/common');
33

44
exports.process = function(file){
55
var Asset = this.model('Asset');
6-
var id = file.source.substring(this.base_dir.length);
6+
var id = file.source.substring(this.base_dir.length).replace(/\\/g, '/');
77
var path = file.params.path;
88
var doc = Asset.findById(id);
99

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
"bluebird": "^2.3.11",
4040
"bunyan": "^1.2.1",
4141
"chalk": "^0.5.1",
42-
"cheerio": "0.17.0",
42+
"cheerio": "0.18.0",
4343
"hexo-front-matter": "0.0.4",
4444
"hexo-fs": "0.0.7",
4545
"hexo-util": "0.0.2",
46-
"js-yaml": "^3.1.0",
46+
"js-yaml": "^3.2.5",
4747
"lodash": "^2.4.1",
4848
"minimist": "1.1.0",
4949
"moment": "2.8.4",

0 commit comments

Comments
 (0)