2023-07-27 16:14:55 +02:00
{{- $page := .page }}
{{- if and (not $page) .context }}
{{- $page = .context }}
2025-01-31 14:57:10 +01:00
{{- $filepath := "[virtual file]" }}{{ with and $page $page.File $page.File.Filename }}{{ $filepath = . }}{{ end }}
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'button' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/5/#5-18-0" $filepath }}
2023-07-27 16:14:55 +02:00
{{- end }}
2023-01-23 22:35:43 +01:00
{{- $color := .color | default "" }}
2022-06-22 20:32:18 +02:00
{{- $content := .content }}
2022-11-28 18:42:51 +01:00
{{- $href := (trim .href " ") | default "" }}
2023-01-23 22:35:43 +01:00
{{- $style := .style | default "default" }}
{{- if and (not $color) (eq (len $color) 0) }}
{{- $style = .style | default "transparent" }}
{{- end }}
2025-02-07 19:55:17 +01:00
{{- $attributes := .attributes | default dict }}
2022-11-28 18:42:51 +01:00
{{- $type := .type | default "" }}
{{- $isButton := false }}
2023-11-29 21:52:14 +01:00
{{- $isLink := false }}
{{- if or $type (strings.HasPrefix $href "javascript:") }}
2022-11-28 18:42:51 +01:00
{{- $isButton = true }}
{{- $href = substr $href (len "javascript:") }}
{{- if not $type }}
{{- $type = "button" }}
{{- end }}
2023-11-29 21:52:14 +01:00
{{- else if not $href }}
{{- else }}
{{- $isLink = true }}
2025-02-07 19:55:17 +01:00
{{- $u := urls.Parse .href }}
{{- if $u.IsAbs }}
{{- partialCached "_relearn/urlExists.gotmpl" (dict "url" .href "page" $page "type" "link") $u.String }}
{{- else }}
{{- $linkObject := partial "_relearn/linkObject.gotmpl" (dict "url" .href "page" $page) }}
{{- if $linkObject }}
{{- $href = partial "_relearn/decoratedLink.gotmpl" (dict "url" .href "page" $page "linkObject" $linkObject "param" "link") }}
{{- else }}
{{- $filepath := "[virtual file]" }}{{ with and $page $page.File $page.File.Filename }}{{ $filepath = . }}{{ end }}
{{- $msg := printf "%q: link '%s' is not a page or a resource" $filepath .href }}
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .href "page" $page "param" "link" "msg" $msg) }}
{{- end }}
{{- end }}
{{- if and (isset . "target") (or (ne (printf "%T" .target) "string") (ne (trim .target " " ) "")) }}
{{- $filepath := "[virtual file]" }}{{ with and $page $page.File $page.File.Filename }}{{ $filepath = . }}{{ end }}
{{- warnf "%q: DEPRECATED parameter 'target' for shortcode 'button' found, use link effects instead; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/7/#7-4-0" $filepath }}
{{- end }}
{{- $attributes = merge $attributes (partial "_relearn/linkAttributes.gotmpl" (dict "url" $href "page" $page "target" .target)) -}}
2022-10-31 21:08:49 +01:00
{{- end }}
2024-09-12 07:55:24 +02:00
{{- $boxStyle := partial "_relearn/boxStyle.gotmpl" (dict "style" $style "title" (or .title $content) "icon" .icon) }}
{{- $title := trim ($boxStyle.title) " " }}
{{- $icon := trim ($boxStyle.icon) " " }}
2022-06-22 20:32:18 +02:00
{{- if and $icon (not (findRE ".*?\\bfa-\\w.*?" $icon)) }}
{{- $icon = printf "fa-fw fas fa-%s" $icon }}
{{- end }}
{{- $iconposition := .iconposition | default "left" }}
2023-11-29 10:33:48 +01:00
{{- with $page -}}
2023-11-29 21:52:14 +01:00
< span class = "btn cstyle {{ if or $isButton $isLink }}interactive {{ end }}{{ $style }}" { { if $ color } } style = "--VARIABLE-BOX-color: {{ $color }};" { { end } } >
2023-11-29 10:33:48 +01:00
{{- if $isButton -}}
2023-11-29 21:52:14 +01:00
< button onclick = "{{ $href | safeJS }}" { { if gt ( len $ type ) 0 } } type = "{{ $type }}" { { end } } >
{{- else if $isLink -}}
2025-02-07 19:55:17 +01:00
< a
2025-02-07 22:15:38 +01:00
{{- range $k, $v := $attributes }}
{{- if $v }}
{{- if eq (printf "%T" $v) "bool" }}
{{- printf " %s" $k | safeHTMLAttr }}
{{- else }}
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
{{- end }}
2025-02-07 19:55:17 +01:00
{{- end }}
2025-02-07 22:15:38 +01:00
{{- end }}>
2023-11-29 10:04:02 +01:00
{{- else -}}
2023-11-29 21:52:14 +01:00
< span >
2022-11-28 18:42:51 +01:00
{{- end }}
2023-11-29 10:04:02 +01:00
{{- if and $icon (eq $iconposition "left") }}< i class = "{{ $icon }}" > < / i > {{ end }}
{{- if and $icon (eq $iconposition "left") $title }} {{ end }}
2023-12-05 15:50:11 +01:00
{{- if $title }}< span class = "title" > {{- $title | safeHTML }}< / span > {{ end }}
2023-11-29 10:04:02 +01:00
{{- if and $icon (eq $iconposition "right") $title }} {{ end }}
{{- if and $icon (eq $iconposition "right") }}< i class = "{{ $icon }}" > < / i > {{ end }}
{{- if $isButton -}}
2022-11-28 18:42:51 +01:00
< / button >
2023-11-29 21:52:14 +01:00
{{- else if $isLink -}}
2022-06-22 20:32:18 +02:00
< / a >
2023-11-29 21:52:14 +01:00
{{- else -}}
< / span >
2023-11-29 10:33:48 +01:00
{{- end -}}
2022-06-22 20:32:18 +02:00
< / span >
{{- end }}