-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
load.js
82 lines (71 loc) · 1.82 KB
/
load.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var _ = require('lodash'),
async = require('async');
/**
* Loads post files.
*
* This function does:
*
* - {% crosslink theme/process %}: Processes theme files
* - {% crosslink theme/watch %}: Watches theme files (When `options.watch` is true)
* - {% crosslink source/process %}: Processes source files
* - {% crosslink source/watch %}: Watches source files (When `options.watch` is true)
* - {% crosslink theme/generate %}: Runs generators
*
* @method load
* @param {Object} [options]
* @param {Boolean} [options.watch=false] Watch source files
* @param {Function} [callback]
* @for post
* @static
*/
module.exports = function(options, callback){
if (!callback){
if (typeof options === 'function'){
callback = options;
options = {};
} else {
callback = function(){};
}
}
options = _.extend({
watch: false
}, options);
var isReady = false;
async.auto({
process_theme: function(next){
hexo.theme.process(next);
},
watch_theme: ['process_theme', function(next){
if (options.watch){
hexo.theme.watch();
hexo.on('processAfter', function(path){
if (isReady && path === hexo.theme_dir){
hexo.theme.generate(options);
}
});
}
next();
}],
process_source: function(next){
hexo.source.process(next);
},
watch_source: ['process_source', function(next){
if (options.watch){
hexo.source.watch();
hexo.on('processAfter', function(path){
if (isReady && path === hexo.source_dir){
hexo.theme.generate(options);
}
});
}
next();
}]
}, function(err){
if (err) return callback(err);
hexo.theme.generate(options, function(err){
if (err) return callback(err);
isReady = true;
callback();
});
});
};