Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable deep merging theme configs by default #4154

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/hexo/default_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module.exports = {
pagination_dir: 'page',
// Extensions
theme: 'landscape',
deepmerge_theme_configs: false,
server: {
cache: false
},
Expand Down
8 changes: 5 additions & 3 deletions lib/hexo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,13 @@ class Hexo extends EventEmitter {

_generateLocals() {
const { config, env, theme, theme_dir } = this;
const ctx = { config: { url: this.config.url } };
const { deepmerge_theme_configs, url, theme_config } = config;
const ctx = { config: { url } };
const localsObj = this.locals.toObject();

if (config.theme_config) {
theme.config = deepMerge(theme.config, config.theme_config);
if (theme_config) {
if (!deepmerge_theme_configs) theme.config = { ...theme.config, ...theme_config };
else theme.config = deepMerge(theme.config, theme_config);
}

class Locals {
Expand Down
14 changes: 14 additions & 0 deletions test/scripts/hexo/hexo.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('Hexo', () => {
const Page = hexo.model('Page');
const Data = hexo.model('Data');
const route = hexo.route;
const defaultConfig = require('../../../lib/hexo/default_config');

function checkStream(stream, expected) {
return testUtil.stream.read(stream).then(data => {
Expand All @@ -36,6 +37,7 @@ describe('Hexo', () => {
hexo.extend.generator.store = {};
// Remove all routes
route.routes = {};
hexo.config = { ...defaultConfig };
});

after(() => fs.rmdir(hexo.base_dir));
Expand Down Expand Up @@ -76,9 +78,21 @@ describe('Hexo', () => {
hexo.config_path.should.eql(pathFn.join(base_dir, '_multiconfig.yml'));
});

it('theme_config - disable deep clone by default', () => {
const hexo = new Hexo(__dirname);
hexo.theme.config = { a: { b: 1, c: 2 } };
hexo.config.theme_config = { a: { b: 3 } };
const Locals = hexo._generateLocals();
const { theme } = new Locals();

theme.a.should.not.have.own.property('c');
theme.a.b.should.eql(3);
});

// Issue #3964
it('theme_config - deep clone', () => {
const hexo = new Hexo(__dirname);
hexo.config.deepmerge_theme_configs = true;
hexo.theme.config = { a: { b: 1, c: 2 } };
hexo.config.theme_config = { a: { b: 3 } };
const Locals = hexo._generateLocals();
Expand Down