multiconfig: allow empty sections

This commit is contained in:
Sören Weber 2024-10-04 15:44:13 +02:00
parent f0a80f64ad
commit 3228097450
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
3 changed files with 14 additions and 5 deletions

View file

@ -13,8 +13,7 @@ The values shown here, reflect the options active in this documentation. The def
## All config options
{{< multiconfig file=hugo >}}
[params]
{{< multiconfig file=hugo section=params >}}
{{% include "config/_default/params.toml" %}}
{{< /multiconfig >}}

View file

@ -11,6 +11,7 @@
@param {string} [file] The file name to display above the rendered code.
@param {bool} [fm=false] If true, render the code as front matter.
@param {bool} [skipHeader=false] If false, omit top level key(s) when rendering a section of site.Data.docs.config.
@param {string} [section] The file name to display above the rendered code.
@returns {template.HTML}
*/}}
@ -33,6 +34,7 @@
{{- else if in (slice "true" true 1) .skipHeader }}
{{- $skipHeader = true }}
{{- end }}
{{- $section := .section }}
{{- /* Define constants. */}}
{{- $delimiters := dict "toml" "+++" "yaml" "---" }}
@ -55,15 +57,22 @@
{{- else }}
{{- $code = $content }}
{{- end }}
{{- /* Remove toml comments. */}}
{{- $code = $code | replaceRE `#.*(\r\n|\r|\n)?` "" }}
{{- $code = trim $code "\n\r\t " }}
{{- if and $section $code }}
{{- $code = printf "[%s]\n%s" $section $code }}
{{- end }}
{{- $params := dict "page" $page "groupid" "config-code" }}
{{- with $file }}
{{- $params = $params | merge (dict "title" (printf "%s%s" . (cond $fm "" "."))) }}
{{- end }}
{{- $contentparam := slice }}
{{- range $langs }}
{{- /* Remove toml comments. */}}
{{- $hCode := $code | replaceRE `#.*(\r\n|\r|\n)?` "" }}
{{- $hCode = $hCode | transform.Remarshal . }}
{{- $hCode := $code }}
{{- if $hCode }}
{{- $hCode = $hCode | transform.Remarshal . }}
{{- end }}
{{- if and $fm (in (slice "toml" "yaml") .) }}
{{- $placeHolder := (index $delimiters .) }}
{{- $hCode = printf "%s\n%s%s\n" $placeHolder $hCode $placeHolder }}

View file

@ -7,4 +7,5 @@
"file" (.Get "file")
"fm" (.Get "fm")
"skipHeader" (.Get "skipHeader")
"section" (.Get "section")
) }}