-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
refactor(hexo): merge theme_config before generation #4360
Conversation
Hi, I'm not sure why you are moving the code? Is it done sooner with your code? Why? |
@tomap Technically, sooner. More details please see #4120 (comment) . In short, @stevenjoezhang want the plugin being able to read |
Yes, this is very important for theme developers. Otherwise additional code is needed to ensure that the configuration in |
Lines 304 to 340 in d117819
I confirm that this patch works fine with |
@stevenjoezhang Then any filter related with post rendering (like Updated Merge theme config during |
My test config: _config.yml theme_config:
foo:
bar: 'bax' theme's _config.yml foo:
baz: 'bos' article.ejs (to display theme config)
In |
@curbengh It is expected behavior. Because site's
Weird. Doesn't happen on my local machine. |
@curbengh Could you please re-verify reloading theme's config? $ npm i sukkaw/hexo#theme_config_ctx Then # _config.yml
theme_config:
foo:
bar: 'bax' # theme's _config.yml
foo:
baz: 'bos' Add following line to the theme template: <% console.log(theme.foo) %>
Update theme's config: # theme's _config.yml
foo:
baz: 'box' Then reload the page should output:
|
This time I tried showing everything inside
After I changed the Looks like my machine's issue. |
@curbengh So it appears that it is not the issue if the PR though. We could dig into the watcher later. Have you run unit test? Is it passed? |
I can confirm it's my machine's issue, not even downgrading to v3.9 helps. I recently migrate Ubuntu -> Solus and I don't recall having this watch issue in Ubuntu. Anyway, I'll debug on my own, don't want to distract this PR. Unit test passed on Node 12 & 14 in my machine. I still prefer to have a theme dev @stevenjoezhang to verify this PR. |
I have added a test case, using |
主題配置文件已經默認了一些配置
我的_config.xxxxx.yml
結果 是生成 qq wechat twitter 按道理 如果_config.xxxxx.yml配置已有 應該按照_config.xxxxx.yml的内容為准,因爲它優先性高. |
Priority is not relevant if a key doesn't have duplicate subkeys, they will be merged, not replaced. # themes/xxxx/_config.yml
item:
lorem: 'a'
ipsum: 'b' # _config.xxxx.yml
item:
dolor: 'c' console.log(theme.config)
item: {
lorem: 'a',
ipsum: 'b',
dolor: 'c'
} A subkey will only be replaced if there is duplicate: # themes/xxxx/_config.yml
item:
lorem: 'a'
ipsum: 'b' # _config.xxxx.yml
item:
lorem: 'c' console.log(theme.config)
item: {
lorem: 'c',
ipsum: 'b'
} |
你这个举例 我明白
qq wechat 这个配置都是属于 item这个key的。 qq和wechat都是item 的值,就好比c是lorem的值,b是ipsum的值, 难道以 -xxx -xxx -xxx 这种形式赋值 都会被识别为几个subkey? |
In your example, const { deepMerge } = require('hexo-util')
const config = {
theme_config: {
item: ['a', 'b']
}
}
const theme = {
config: {
item: ['c']
}
}
theme.config = deepMerge(theme.config, config.theme_config);
console.log(theme.config)
// { item: [ 'c', 'a', 'b' ] } If you want to replace the original |
Why not overwrite array instead of combine arrays? Is there any special reason? I think for themes, overwriting array is more suitable to providing some example configurations without disturbing the user. Or just provide a configuration to decide whether to overwrite the array or merge the array? |
What does it do?
#4120, #4120 (comment), #3890 (comment)
This PR closes #3890.
How to test
Screenshots
Pull request tasks