Files
FixIt/layouts/_markup/render-codeblock-json.html
T
Cell d55d53741d fix: dict type page parameters fall back to site parameters using merge behavior (#670)
> The `Param` method on a `Page` object looks for the given `KEY` in page parameters, and returns the corresponding value. If it cannot find the `KEY `in page parameters, it looks for the `KEY` in site parameters. If it cannot find the `KEY` in either location, the Param method returns `nil`.
>
> See: https://gohugo.io/methods/page/param/

So `.Page.Param` is only suitable for simple types.
2025-12-30 11:23:25 +08:00

22 lines
947 B
HTML

{{- $jsonViewer := .Attributes | merge .Page.Params.jsonViewer | merge .Page.Site.Params.jsonViewer -}}
{{- if $jsonViewer.enable -}}
{{- $attrs := printf `expand-depth="%v"` $jsonViewer.expanddepth -}}
{{- $copyable := false -}}
{{- with $jsonViewer.copyable -}}
{{- $copyable = dict "copyText" (T "assets.copyText") "copiedText" (T "assets.copiedText") -}}
{{- end -}}
{{- with $jsonViewer.sort -}}
{{- $attrs = " sort" | add $attrs -}}
{{- end -}}
{{- with $jsonViewer.boxed -}}
{{- $attrs = " boxed" | add $attrs -}}
{{- end -}}
<json-viewer value="{{ .Inner | jsonify }}" {{ $attrs | safeHTMLAttr }}{{ with $copyable}} copyable="{{ . | jsonify }}"{{ end }}></json-viewer>
{{- .Page.Store.Set "hasJsonViewer" true -}}
{{- if eq hugo.Context.MarkupScope "home" -}}
{{- site.Home.Store.Set "hasJsonViewer" true -}}
{{- end -}}
{{- else -}}
{{- partial "plugin/code-block-wrapper.html" . -}}
{{- end -}}