{{/* Adapted from https://github.com/CloudCannon/bookshop/blob/main/hugo/v3/core/helpers/component.html */}} {{/* Renders a single Bookshop component, wrapping in in a live editing context tag. Expects a slice: [ , # Component name <_> # Component props ] */}} {{- $component_name := index . 0 -}} {{- $component_props := index . 1 -}} {{- $class := index . 2 | default "p-0" -}} {{- $bgclass := index . 3 | default "" -}} {{- $padding := partial "utilities/GetPadding.html" -}} {{- with index $component_props "padding" }}{{ $padding = dict "x" . "y" . }}{{ end -}} {{- $component_path := partial "_bookshop/helpers/component_key" $component_name -}} {{- $flat_component_path := partial "_bookshop/helpers/flat_component_key" $component_name -}} {{- $resolved_component := false -}} {{- if templates.Exists ( printf "_partials/%s" $component_path ) -}} {{- $resolved_component = $component_path -}} {{- else if templates.Exists ( printf "_partials/%s" $flat_component_path ) -}} {{- $resolved_component = $flat_component_path -}} {{- end -}} {{- if $resolved_component -}} {{- $id := index $component_props "id" -}} {{- $cover := index $component_props "cover" -}} {{- $background := index $component_props "background" -}} {{- $backdrop := "" -}} {{- $fluid := index $component_props "fluid" | default true -}} {{- $style := index $component_props "wrapper" -}} {{- $width := index $component_props "width" -}} {{- $justify := index $component_props "justify" | default "start" -}} {{- $paddingOuter := cond (ne $component_name "separator") (printf "px-xxl-0 px-%d py-0" $padding.x) "" -}} {{- $padding := cond (ne $component_name "separator") (printf "px-%d %spy-%d" $padding.x (cond $fluid "px-xxl-0 " "") $padding.y) "" -}} {{- $wrapper := $style }} {{ with $background }} {{ $wrapper = partial "utilities/GetBackgroundStyle.html" (dict "background" . "class" $style) }} {{ if reflect.IsMap $background }} {{ with $background.backdrop }}{{ $wrapper = "" }}{{ $backdrop = . }}{{ end }} {{ end }} {{ end }} {{- $theme := index $component_props "theme" -}} {{- $overlayMode := (or (index $component_props "overlay-mode") page.Params.overlayMode) | default "dark" -}} {{ if not $backdrop }}{{ $overlayMode = page.Params.overlayMode }}{{ end }} {{ if eq $overlayMode "none" }}{{ $overlayMode = "" }}{{ end }} {{ (printf "" $component_name) | safeHTML }} {{ if not $fluid }}
{{ end }}
{{- if $backdrop -}} {{ partial "assets/live-image.html" (dict "src" $backdrop "class" (printf "background-img-fluid %s" $bgclass) "title" (T "backgroundImage")) }} {{- end -}} {{ $col := cond (and $width (lt $width 12)) (printf "col-12 col-md-%d" $width) "" }}
{{ with $col }}
{{ partial $resolved_component $component_props }}
{{ else }} {{ partial $resolved_component $component_props }} {{ end}}
{{ if not $fluid }}
{{ end }} {{ "" | safeHTML }} {{- else -}} {{- $file_loc := slicestr $component_path 9 -}} {{- $flat_file_loc := slicestr $flat_component_path 9 -}} {{- partial "_bookshop/errors/err" (printf "Component \"%s\" does not exist.\n Create this component by placing a file in your bookshop at %s or %s" $component_name $file_loc $flat_file_loc) -}} {{- end -}}