Skip to content

Commit

Permalink
refactor(hexo): merge theme config during watch
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jun 16, 2020
1 parent cbf2999 commit 405df35
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/hexo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ class Hexo extends EventEmitter {
this.source.watch(),
this.theme.watch()
]);
}).then(() => {
// Merge hexo.config.theme_config into hexo.theme.config before post rendering & generating
// config.theme_config has "_config.[theme].yml" merged in load_theme_config.js
if (this.config.theme_config) {
this.theme.config = deepMerge(this.theme.config, this.config.theme_config);
}
}).then(() => {
this.source.on('processAfter', this._watchBox);
this.theme.on('processAfter', this._watchBox);
Expand Down
22 changes: 22 additions & 0 deletions test/scripts/hexo/hexo.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,28 @@ describe('Hexo', () => {

it('watch() - theme', () => testWatch(join(hexo.theme_dir, 'source')));

it('watch() - merge theme config', async () => {
const hexo = new Hexo(__dirname);

hexo.theme.config = { a: { b: 1, c: 2 } };
hexo.config.theme_config = { a: { b: 3 } };

await hexo.watch();

const { config: themeConfig } = hexo.theme;

themeConfig.a.should.have.own.property('c');
themeConfig.a.b.should.eql(3);

const Locals = hexo._generateLocals();
const { theme: themeLocals } = new Locals();

themeLocals.a.should.have.own.property('c');
themeLocals.a.b.should.eql(3);

hexo.unwatch();
});

// it('unwatch()'); missing-unit-test

it('exit()', () => {
Expand Down

0 comments on commit 405df35

Please sign in to comment.