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

Allow "smart merging of config" for language specific configs. #10620

Closed
cmpute opened this issue Jan 14, 2023 · 9 comments
Closed

Allow "smart merging of config" for language specific configs. #10620

cmpute opened this issue Jan 14, 2023 · 9 comments
Assignees
Milestone

Comments

@cmpute
Copy link

cmpute commented Jan 14, 2023

Choosing how the config is merged between user config and theme config is supported by #8633, but the merge between language specific config and base config seems to be not supported.

If I have a theme config

[params.comments]
color = "aaa"
title = "xxx"

then a language specific config

[[language.en]]
[language.en.params.comments]
title = "yyy"

then the color config will not be merged into the final config of that language. Maybe it's feasible but just I don't know how to.

@jmooring
Copy link
Member

I think the current behavior is correct, and it makes sense to me. A language key has greater specificity than a root key (similar to the way CSS rules work). You can see how this works, even without a theme.

Without a language params table:

[params.comments]
title = 'root'

{{ site.Params.comments }} --> map[title:root]

With a language params table, but without any key/value pairs:

[params.comments]
title = 'root'

[languages.en.params.comments]

{{ site.Params.comments }} --> map[]

With a populated language params table:

[params.comments]
title = 'root'

[languages.en.params.comments]
title = 'en'

{{ site.Params.comments }} --> map[title:en]

@cmpute
Copy link
Author

cmpute commented Jan 15, 2023

I understand that language config has higher priority than the normal config. To make it clearer, what I would like to see is the ability to set color = "aaa" for language en as well if I have the following lines in the config file:

[params.comments]
color = "aaa"
title = "xxx"
[[language.en]]
[language.en.params.comments]
title = "yyy"

In the current behavior, the color setting will just be discarded instead of being merged. So {{ site.Params.comments.color }} is empty. It will be great if we can also support a _merge option to opt-in the deep merging behavior.

@istr
Copy link

istr commented Jan 15, 2023

Might be related to #10208.

For both mediaTypes and outputFormats there is code in place to explicitly merge the language configuration with highest priority, see

// Add language last, if set, so it gets precedence.

But might be unrelated as well, as there is special handling for language based configuration in the merge logic:

// Languages is currently a special case.

@bep bep removed the NeedsTriage label Jan 17, 2023
@bep bep added this to the v0.109.0 milestone Jan 17, 2023
@bep bep added Enhancement and removed Proposal labels Jan 17, 2023
@bep
Copy link
Member

bep commented Jan 17, 2023

@cmpute I agree that we should do this. As @istr has pointed out, the probable reason why this isn't working as you expect today is that we the params language merging isn't currently a part of the "total config merge", but a shallow merge done when you use this for a given language. I have a branch where I'm currently consolidating all config into one struct (mostly for documentation purposes), but it should also allow me to improve on this.

@bep bep modified the milestones: v0.109.0, v0.111.0 Jan 26, 2023
@bep bep modified the milestones: v0.111.0, v0.112.0 Feb 15, 2023
@bep bep self-assigned this Apr 14, 2023
bep added a commit to bep/hugo that referenced this issue Apr 15, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
@bep bep modified the milestones: v0.112.0, v0.113.0 Apr 15, 2023
bep added a commit to bep/hugo that referenced this issue Apr 27, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
bep added a commit to bep/hugo that referenced this issue Apr 27, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
bep added a commit to bep/hugo that referenced this issue May 11, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
bep added a commit to bep/hugo that referenced this issue May 12, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
bep added a commit to bep/hugo that referenced this issue May 12, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
bep added a commit to bep/hugo that referenced this issue May 12, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
bep added a commit to bep/hugo that referenced this issue May 12, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
bep added a commit to bep/hugo that referenced this issue May 12, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
bep added a commit to bep/hugo that referenced this issue May 13, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
bep added a commit to bep/hugo that referenced this issue May 15, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
bep added a commit to bep/hugo that referenced this issue May 15, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
bep added a commit to bep/hugo that referenced this issue May 16, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
bep added a commit to bep/hugo that referenced this issue May 16, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
bep added a commit to bep/hugo that referenced this issue May 16, 2023
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes gohugoio#10896
Closes gohugoio#10620
@bep bep closed this as completed in 241b21b May 16, 2023
@CXwudi
Copy link

CXwudi commented May 16, 2023

Huge thanks for solving this. Now I am ready to significant simplify my dual-language blog config files 😄

@istr
Copy link

istr commented May 17, 2023

Yes, thank you @bep . The rewrite / consolidation in 241b21b is really huge and a great step forwards.

@bep
Copy link
Member

bep commented May 17, 2023

@istr thanks; fun story: Sunday when I was almost done I thought, I'm going to run some benchmarks just to make sure I haven't messed up ... Turned out everything was about 20% slower and more memory hungry. It, of course, had a simple explanation (reparsing of the Go templates for each site), but it was a moment there where I almost threw in the towel :-)

@istr
Copy link

istr commented May 17, 2023

a moment there where I almost threw in the towel

Oh yes, this kind of moment. I know it only too well...

@github-actions
Copy link

github-actions bot commented Jun 8, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants