Misc config loading fixes

The main motivation behind this is simplicity and correctnes, but the new small config library is also faster:

```
BenchmarkDefaultConfigProvider/Viper-16         	  252418	      4546 ns/op	    2720 B/op	      30 allocs/op
BenchmarkDefaultConfigProvider/Custom-16        	  450756	      2651 ns/op	    1008 B/op	       6 allocs/op
```

Fixes #8633
Fixes #8618
Fixes #8630
Updates #8591
Closes #6680
Closes #5192
This commit is contained in:
Bjørn Erik Pedersen committed 2021-06-14 17:00:32 +02:00
1 parent 0b4117f7f6
commit ef73ffc3bc
4 files changed
+91 -5

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ footnotereturnlinkcontents = "↩"
languageCode = "en-us" languageCode = "en-us"
title = "Hugo" title = "Hugo"
ignoreErrors = ["error-remote-getjson"] ignoreErrors = ["error-remote-getjson", "err-missing-instagram-accesstoken"]
googleAnalytics = "UA-7131036-4" googleAnalytics = "UA-7131036-4"
@@ -80,6 +80,26 @@ Considering the structure above, when running `hugo --environment staging`, Hugo
{{% note %}} {{% note %}}
Default environments are __development__ with `hugo server` and __production__ with `hugo`. Default environments are __development__ with `hugo server` and __production__ with `hugo`.
{{%/ note %}} {{%/ note %}}
## Merge Configuration from Themes
{{< new-in "0.84.0" >}} The configuration merge described below was improved in Hugo 0.84.0 and made fully configurable. The big change/improvement was that we now, by default, do deep merging of `params` maps from themes.
The configuration value for `_merge` can be one of:
none
: No merge.
shallow
: Only add values for new keys.
shallow
: Add values for new keys, merge existing.
Note that you don't need to be so verbose as in the default setup below; a `_merge` value higher up will be inherited if not set.
{{< code-toggle config="mergeStrategy" skipHeader=true />}}
## All Configuration Settings ## All Configuration Settings
The following is the full list of Hugo-defined variables with their default The following is the full list of Hugo-defined variables with their default
+59
View File
@@ -1587,6 +1587,65 @@
"preserveTOC": false "preserveTOC": false
} }
}, },
"mergeStrategy": {
"build": {
"_merge": "none"
},
"caches": {
"_merge": "none"
},
"frontmatter": {
"_merge": "none"
},
"imaging": {
"_merge": "none"
},
"languages": {
"_merge": "none",
"en": {
"_merge": "none",
"menus": {
"_merge": "shallow"
},
"params": {
"_merge": "deep"
}
}
},
"markup": {
"_merge": "none"
},
"mediatypes": {
"_merge": "shallow"
},
"menus": {
"_merge": "shallow"
},
"minify": {
"_merge": "none"
},
"module": {
"_merge": "none"
},
"outputformats": {
"_merge": "shallow"
},
"params": {
"_merge": "deep"
},
"permalinks": {
"_merge": "none"
},
"related": {
"_merge": "none"
},
"sitemap": {
"_merge": "none"
},
"taxonomies": {
"_merge": "none"
}
},
"minify": { "minify": {
"minifyOutput": false, "minifyOutput": false,
"disableHTML": false, "disableHTML": false,
+11 -4
View File
@@ -5,6 +5,9 @@
{{ $sections := (split . ".") }} {{ $sections := (split . ".") }}
{{ $configSection := index $.Site.Data.docs.config $sections }} {{ $configSection := index $.Site.Data.docs.config $sections }}
{{ $code = dict $sections $configSection }} {{ $code = dict $sections $configSection }}
{{ if $.Get "skipHeader"}}
{{ $code = $configSection }}
{{ end }}
{{ else }} {{ else }}
{{ $code = $.Inner }} {{ $code = $.Inner }}
{{ end }} {{ end }}
@@ -12,10 +15,15 @@
<div class="code relative" {{ with $file }}id="{{ . | urlize}}"{{ end }}> <div class="code relative" {{ with $file }}id="{{ . | urlize}}"{{ end }}>
<div class="code-nav flex flex-nowrap items-stretch"> <div class="code-nav flex flex-nowrap items-stretch">
{{- with $file -}} {{- with $file -}}
<div class="san-serif f6 dib lh-solid pl2 pv2 mr2">{{ . }}.</div> <div class="san-serif f6 dib lh-solid pl2 pv2 mr2">
{{ . }}.
</div>
{{- end -}} {{- end -}}
{{ range $langs }} {{ range $langs }}
<button data-toggle-tab="{{ . }}" class="tab-button {{ cond (eq . "yaml") "active" ""}} ba san-serif f6 dib lh-solid ph2 pv2">{{ . }}</button>&nbsp; <button data-toggle-tab="{{ . }}" class="tab-button {{ cond (eq . "yaml") "active" ""}} ba san-serif f6 dib lh-solid ph2 pv2">
{{ . }}
</button>
&nbsp;
{{ end }} {{ end }}
</div> </div>
<div class="tab-content"> <div class="tab-content">
@@ -24,8 +32,7 @@
{{ highlight ($code | transform.Remarshal . | safeHTML) . ""}} {{ highlight ($code | transform.Remarshal . | safeHTML) . ""}}
</div> </div>
{{ if ne ($.Get "copy") "false" }} {{ if ne ($.Get "copy") "false" }}
<button class="needs-js copy copy-toggle bg-accent-color-dark f6 absolute top-0 right-0 lh-solid hover-bg-primary-color-dark bn white ph3 pv2" title="Copy this code to your clipboard." data-clipboard-action="copy" aria-label="copy button"> <button class="needs-js copy copy-toggle bg-accent-color-dark f6 absolute top-0 right-0 lh-solid hover-bg-primary-color-dark bn white ph3 pv2" title="Copy this code to your clipboard." data-clipboard-action="copy" aria-label="copy button"></button>
</button>
{{/* Functionality located within filesaver.js The copy here is located in the css with .copy class so it can be replaced with JS on success */}} {{/* Functionality located within filesaver.js The copy here is located in the css with .copy class so it can be replaced with JS on success */}}
{{end}} {{end}}
{{ end }} {{ end }}