Skip to content

Commit 61941e7

Browse files
committed
Merge config instead of extend
1 parent 8cca1f9 commit 61941e7

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

lib/hexo/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function Hexo(base, args) {
6868
tag: new extend.Tag()
6969
};
7070

71-
this.config = _.clone(defaultConfig);
71+
this.config = _.cloneDeep(defaultConfig);
7272

7373
this.log = createLogger(this.env);
7474

lib/hexo/load_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = function(ctx) {
2828

2929
ctx.log.debug('Config loaded: %s', chalk.magenta(tildify(configPath)));
3030

31-
config = _.extend(ctx.config, config);
31+
config = _.merge(ctx.config, config);
3232
ctx.config_path = configPath;
3333

3434
config.root = config.root.replace(/\/*$/, '/');

test/scripts/filters/backtick_code_block.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('Backtick code block', function() {
2424

2525
beforeEach(function() {
2626
// Reset config
27-
hexo.config.highlight = _.clone(defaultConfig.highlight);
27+
hexo.config.highlight = _.cloneDeep(defaultConfig.highlight);
2828
});
2929

3030
it('disabled', function() {

test/scripts/hexo/load_config.js

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ describe('Load config', function() {
1313

1414
hexo.env.init = true;
1515

16-
function reset() {
17-
hexo.config = _.clone(defaultConfig);
18-
}
19-
2016
before(function() {
2117
return fs.mkdirs(hexo.base_dir).then(function() {
2218
return hexo.init();
@@ -27,6 +23,10 @@ describe('Load config', function() {
2723
return fs.rmdir(hexo.base_dir);
2824
});
2925

26+
beforeEach(function() {
27+
hexo.config = _.cloneDeep(defaultConfig);
28+
});
29+
3030
it('config file does not exist', function() {
3131
return loadConfig(hexo).then(function() {
3232
hexo.config.should.eql(defaultConfig);
@@ -40,8 +40,7 @@ describe('Load config', function() {
4040
return loadConfig(hexo);
4141
}).then(function() {
4242
hexo.config.foo.should.eql(1);
43-
44-
reset();
43+
}).finally(function() {
4544
return fs.unlink(configPath);
4645
});
4746
});
@@ -53,8 +52,7 @@ describe('Load config', function() {
5352
return loadConfig(hexo);
5453
}).then(function() {
5554
hexo.config.baz.should.eql(3);
56-
57-
reset();
55+
}).finally(function() {
5856
return fs.unlink(configPath);
5957
});
6058
});
@@ -66,8 +64,7 @@ describe('Load config', function() {
6664
return loadConfig(hexo);
6765
}).then(function() {
6866
hexo.config.should.eql(defaultConfig);
69-
70-
reset();
67+
}).finally(function() {
7168
return fs.unlink(configPath);
7269
});
7370
});
@@ -79,8 +76,7 @@ describe('Load config', function() {
7976
return loadConfig(hexo);
8077
}).then(function() {
8178
hexo.config.foo.should.eql(1);
82-
83-
reset();
79+
}).finally(function() {
8480
hexo.config_path = pathFn.join(hexo.base_dir, '_config.yml');
8581
return fs.unlink(configPath);
8682
});
@@ -95,8 +91,7 @@ describe('Load config', function() {
9591
}).then(function() {
9692
hexo.config.foo.should.eql(2);
9793
hexo.config_path.should.eql(realPath);
98-
99-
reset();
94+
}).finally(function() {
10095
hexo.config_path = pathFn.join(hexo.base_dir, '_config.yml');
10196
return fs.unlink(realPath);
10297
});
@@ -113,8 +108,7 @@ describe('Load config', function() {
113108
}).then(function() {
114109
hexo.config.root.should.eql('foo/');
115110
hexo.config.url.should.eql('http://hexo.io');
116-
117-
reset();
111+
}).finally(function() {
118112
return fs.unlink(hexo.config_path);
119113
});
120114
});
@@ -124,8 +118,7 @@ describe('Load config', function() {
124118
return loadConfig(hexo);
125119
}).then(function() {
126120
hexo.public_dir.should.eql(pathFn.resolve(hexo.base_dir, 'foo') + pathFn.sep);
127-
128-
reset();
121+
}).finally(function() {
129122
return fs.unlink(hexo.config_path);
130123
});
131124
});
@@ -135,8 +128,7 @@ describe('Load config', function() {
135128
return loadConfig(hexo);
136129
}).then(function() {
137130
hexo.source_dir.should.eql(pathFn.resolve(hexo.base_dir, 'bar') + pathFn.sep);
138-
139-
reset();
131+
}).finally(function() {
140132
return fs.unlink(hexo.config_path);
141133
});
142134
});
@@ -149,8 +141,23 @@ describe('Load config', function() {
149141
hexo.theme_dir.should.eql(pathFn.join(hexo.base_dir, 'themes', 'test') + pathFn.sep);
150142
hexo.theme_script_dir.should.eql(pathFn.join(hexo.theme_dir, 'scripts') + pathFn.sep);
151143
hexo.theme.base.should.eql(hexo.theme_dir);
144+
}).finally(function() {
145+
return fs.unlink(hexo.config_path);
146+
});
147+
});
148+
149+
it('merge config', function() {
150+
var content = [
151+
'highlight:',
152+
' tab_replace: yoooo'
153+
].join('\n');
152154

153-
reset();
155+
return fs.writeFile(hexo.config_path, content).then(function() {
156+
return loadConfig(hexo);
157+
}).then(function() {
158+
hexo.config.highlight.enable.should.be.true;
159+
hexo.config.highlight.tab_replace.should.eql('yoooo');
160+
}).finally(function() {
154161
return fs.unlink(hexo.config_path);
155162
});
156163
});

0 commit comments

Comments
 (0)