Files
hextra/layouts/_shortcodes/badge.html
T

54 lines
1.4 KiB
HTML
Raw Normal View History

{{- /*
A shortcode to create a badge.
@param {string} content The content of the badge.
2025-08-23 15:42:23 +02:00
@param {string} color The color of the badge.
@param {string} class The class of the badge.
@param {string} link The link of the badge.
@param {string} icon The icon of the badge.
or
@param {string} 0 The content of the badge.
2025-08-23 15:42:23 +02:00
@example {{< badge content="Badge" color="blue" >}}
@example {{< badge "Badge" >}}
*/ -}}
2024-09-22 22:12:22 +01:00
{{- if .IsNamedParams -}}
{{- $content := .Get "content" -}}
2025-08-23 15:42:23 +02:00
{{- $color := .Get "color" | default (.Get "type") | default "" -}}{{- /* Compatibility with previous parameter. */ -}}
2024-09-22 22:12:22 +01:00
{{- $class := .Get "class" | default "" -}}
{{- $link := .Get "link" | default "" -}}
{{- $icon := .Get "icon" | default "" -}}
2025-08-23 15:42:23 +02:00
{{- $border := not (eq (.Get "border") false) | default true }}
2024-09-22 22:12:22 +01:00
{{- if $link -}}
<a href="{{ $link }}" title="{{ $content | plainify }}" target="_blank">
{{- partial "shortcodes/badge.html" (dict
"content" $content
2025-08-23 15:42:23 +02:00
"color" $color
2024-09-22 22:12:22 +01:00
"class" $class
2025-08-23 15:42:23 +02:00
"border" $border
"icon" $icon
2024-09-22 22:12:22 +01:00
)
-}}
</a>
{{- else -}}
{{- partial "shortcodes/badge.html" (dict
"content" $content
2025-08-23 15:42:23 +02:00
"color" $color
2024-09-22 22:12:22 +01:00
"class" $class
2025-08-23 15:42:23 +02:00
"border" $border
"icon" $icon
2024-09-22 22:12:22 +01:00
)
-}}
{{- end -}}
{{- else -}}
{{- $content := .Get 0 -}}
{{- partial "shortcodes/badge.html" (dict
"content" $content
"border" true
)
-}}
{{- end -}}