2021-12-13 15:04:12 -05:00
|
|
|
{{- /*
|
2023-08-30 13:23:47 -04:00
|
|
|
Renders syntax-highlighted configuration data in JSON, TOML, and YAML formats.
|
2021-12-13 15:04:12 -05:00
|
|
|
|
2023-08-30 13:23:47 -04:00
|
|
|
@param {string} [config] The section of site.Data.docs.config to render.
|
|
|
|
@param {bool} [copy=true] If true, display a copy to clipboard button.
|
|
|
|
@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.
|
2023-05-22 10:43:12 -04:00
|
|
|
|
2023-08-30 13:23:47 -04:00
|
|
|
@returns {template.HTML}
|
2023-05-22 10:43:12 -04:00
|
|
|
*/}}
|
2021-12-13 15:04:12 -05:00
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
{{- /* Initialize. */}}
|
|
|
|
{{- $config := "" }}
|
2023-08-30 13:23:47 -04:00
|
|
|
{{- $dataKey := "" }}
|
2023-05-22 10:43:12 -04:00
|
|
|
{{- $copy := true }}
|
|
|
|
{{- $file := "" }}
|
|
|
|
{{- $fm := false }}
|
|
|
|
{{- $skipHeader := false }}
|
2021-12-13 15:04:12 -05:00
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
{{- /* Get parameters. */}}
|
|
|
|
{{- $config = .Get "config" }}
|
2023-08-30 13:23:47 -04:00
|
|
|
{{- $dataKey = .Get "dataKey" }}
|
2023-05-22 10:43:12 -04:00
|
|
|
{{- $file = .Get "file" }}
|
|
|
|
{{- if in (slice "false" false 0) (.Get "copy") }}
|
|
|
|
{{- $copy = false }}
|
2023-08-30 13:23:47 -04:00
|
|
|
{{- else if in (slice "true" true 1) (.Get "copy") }}
|
2023-05-22 10:43:12 -04:00
|
|
|
{{- $copy = true }}
|
|
|
|
{{- end }}
|
|
|
|
{{- if in (slice "false" false 0) (.Get "fm") }}
|
|
|
|
{{- $fm = false }}
|
2023-08-30 13:23:47 -04:00
|
|
|
{{- else if in (slice "true" true 1) (.Get "fm") }}
|
2023-05-22 10:43:12 -04:00
|
|
|
{{- $fm = true }}
|
|
|
|
{{- end }}
|
|
|
|
{{- if in (slice "false" false 0) (.Get "skipHeader") }}
|
|
|
|
{{- $skipHeader = false }}
|
2023-08-30 13:23:47 -04:00
|
|
|
{{- else if in (slice "true" true 1) (.Get "skipHeader") }}
|
2023-05-22 10:43:12 -04:00
|
|
|
{{- $skipHeader = true }}
|
|
|
|
{{- end }}
|
2021-12-13 15:04:12 -05:00
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
{{- /* Define constants. */}}
|
|
|
|
{{- $delimiters := dict "toml" "+++" "yaml" "---" }}
|
|
|
|
{{- $langs := slice "yaml" "toml" "json" }}
|
|
|
|
{{- $placeHolder := "#-hugo-placeholder-#" }}
|
2021-12-13 15:04:12 -05:00
|
|
|
|
2023-05-22 10:43:12 -04:00
|
|
|
{{- /* Render. */}}
|
|
|
|
{{- $code := "" }}
|
2023-08-30 13:23:47 -04:00
|
|
|
{{- if $config }}
|
2023-05-27 10:59:59 -04:00
|
|
|
{{- $file = $file | default "hugo" }}
|
2023-08-30 13:23:47 -04:00
|
|
|
{{- $sections := (split $config ".") }}
|
2023-05-22 10:43:12 -04:00
|
|
|
{{- $configSection := index $.Site.Data.docs.config $sections }}
|
|
|
|
{{- $code = dict $sections $configSection }}
|
|
|
|
{{- if $skipHeader }}
|
|
|
|
{{- $code = $configSection }}
|
|
|
|
{{- end }}
|
2023-08-30 13:23:47 -04:00
|
|
|
{{- else if $dataKey }}
|
|
|
|
{{- $file = $file | default $dataKey }}
|
|
|
|
{{- $sections := (split $dataKey ".") }}
|
|
|
|
{{- $code = index $.Site.Data.docs $sections }}
|
2023-05-22 10:43:12 -04:00
|
|
|
{{- else }}
|
|
|
|
{{- $code = $.Inner }}
|
2021-12-13 15:04:12 -05:00
|
|
|
{{- end }}
|
|
|
|
<div class="code relative" {{ with $file }}id="{{ . | urlize }}"{{ end }}>
|
2021-06-18 11:49:54 -04:00
|
|
|
<div class="code-nav flex flex-nowrap items-stretch">
|
2021-12-13 15:04:12 -05:00
|
|
|
{{- with $file }}
|
2021-06-18 11:49:54 -04:00
|
|
|
<div class="san-serif f6 dib lh-solid pl2 pv2 mr2">
|
2023-05-22 10:43:12 -04:00
|
|
|
{{ . }}{{ if not $fm }}.{{ end }}
|
2021-06-18 11:49:54 -04:00
|
|
|
</div>
|
2023-05-22 10:43:12 -04:00
|
|
|
{{- end }}
|
2021-12-13 15:04:12 -05:00
|
|
|
{{- range $langs }}
|
2023-08-30 13:23:47 -04:00
|
|
|
<button
|
|
|
|
data-toggle-tab="{{ . }}"
|
|
|
|
class="tab-button {{ cond (eq . "yaml") "active" "" }} ba san-serif f6 dib lh-solid ph2 pv2">
|
2021-06-18 11:49:54 -04:00
|
|
|
{{ . }}
|
|
|
|
</button>
|
|
|
|
|
2021-12-13 15:04:12 -05:00
|
|
|
{{- end }}
|
2021-06-18 11:49:54 -04:00
|
|
|
</div>
|
|
|
|
<div class="tab-content">
|
2021-12-13 15:04:12 -05:00
|
|
|
{{- range $langs }}
|
2023-08-30 13:23:47 -04:00
|
|
|
<div
|
|
|
|
data-pane="{{ . }}"
|
|
|
|
class="code-copy-content nt3 tab-pane {{ cond (eq . "yaml") "active" "" }}">
|
2023-05-22 10:43:12 -04:00
|
|
|
{{- $hCode := $code | transform.Remarshal . }}
|
|
|
|
{{- if and $fm (in (slice "toml" "yaml") .) }}
|
|
|
|
{{- $hCode = printf "%s\n%s\n%s" $placeHolder $hCode $placeHolder }}
|
|
|
|
{{- end }}
|
2021-12-13 15:04:12 -05:00
|
|
|
{{- $hCode = $hCode | replaceRE `\n+` "\n" }}
|
|
|
|
{{ highlight $hCode . "" | replaceRE $placeHolder (index $delimiters .) | safeHTML }}
|
2021-06-18 11:49:54 -04:00
|
|
|
</div>
|
2021-12-13 15:04:12 -05:00
|
|
|
{{- if $copy }}
|
2023-08-30 13:23:47 -04:00
|
|
|
<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>
|
2023-05-22 10:43:12 -04:00
|
|
|
{{- /* 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 }}
|
2021-12-13 15:04:12 -05:00
|
|
|
{{- end }}
|
2021-06-18 11:49:54 -04:00
|
|
|
</div>
|
2019-12-15 04:35:09 -05:00
|
|
|
</div>
|