From d392893cd73dc00c927f342778f6dca9628d328e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 9 Jun 2021 10:58:18 +0200 Subject: 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 --- docs/config.toml | 2 +- docs/content/en/getting-started/configuration.md | 20 ++++++++ docs/data/docs.json | 59 ++++++++++++++++++++++++ docs/layouts/shortcodes/code-toggle.html | 59 +++++++++++++----------- 4 files changed, 113 insertions(+), 27 deletions(-) (limited to 'docs') diff --git a/docs/config.toml b/docs/config.toml index efa1b0573..d21f6f172 100644 --- a/docs/config.toml +++ b/docs/config.toml @@ -7,7 +7,7 @@ footnotereturnlinkcontents = "↩" languageCode = "en-us" title = "Hugo" - ignoreErrors = ["error-remote-getjson"] + ignoreErrors = ["error-remote-getjson", "err-missing-instagram-accesstoken"] googleAnalytics = "UA-7131036-4" diff --git a/docs/content/en/getting-started/configuration.md b/docs/content/en/getting-started/configuration.md index 48a4af0c9..fd8c65d04 100644 --- a/docs/content/en/getting-started/configuration.md +++ b/docs/content/en/getting-started/configuration.md @@ -80,6 +80,26 @@ Considering the structure above, when running `hugo --environment staging`, Hugo {{% note %}} Default environments are __development__ with `hugo server` and __production__ with `hugo`. {{%/ 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 The following is the full list of Hugo-defined variables with their default diff --git a/docs/data/docs.json b/docs/data/docs.json index 2b17ad8af..b927f8d0a 100644 --- a/docs/data/docs.json +++ b/docs/data/docs.json @@ -1587,6 +1587,65 @@ "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": { "minifyOutput": false, "disableHTML": false, diff --git a/docs/layouts/shortcodes/code-toggle.html b/docs/layouts/shortcodes/code-toggle.html index da4b00719..0b92d520d 100644 --- a/docs/layouts/shortcodes/code-toggle.html +++ b/docs/layouts/shortcodes/code-toggle.html @@ -1,34 +1,41 @@ {{ $file := .Get "file" }} {{ $code := "" }} {{ with .Get "config" }} -{{ $file = $file | default "config" }} -{{ $sections := (split . ".") }} -{{ $configSection := index $.Site.Data.docs.config $sections }} -{{ $code = dict $sections $configSection }} + {{ $file = $file | default "config" }} + {{ $sections := (split . ".") }} + {{ $configSection := index $.Site.Data.docs.config $sections }} + {{ $code = dict $sections $configSection }} + {{ if $.Get "skipHeader"}} + {{ $code = $configSection }} + {{ end }} {{ else }} -{{ $code = $.Inner }} + {{ $code = $.Inner }} {{ end }} {{ $langs := (slice "yaml" "toml" "json") }}
-
- {{- with $file -}} -
{{ . }}.
- {{- end -}} - {{ range $langs }} -   - {{ end }} -
-
- {{ range $langs }} -
- {{ highlight ($code | transform.Remarshal . | safeHTML) . ""}} -
- {{ if ne ($.Get "copy") "false" }} - - {{/* 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 }} -
- +
+ {{- with $file -}} +
+ {{ . }}. +
+ {{- end -}} + {{ range $langs }} + +   + {{ end }} +
+
+ {{ range $langs }} +
+ {{ highlight ($code | transform.Remarshal . | safeHTML) . ""}} +
+ {{ if ne ($.Get "copy") "false" }} + + {{/* 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 }} +
+
-- cgit v1.2.3