Introduce badge shortcode to replace HTML code

This commit is contained in:
mark
2023-08-27 06:09:42 +02:00
parent 9f437c0576
commit ddc19e40ef
2 changed files with 41 additions and 7 deletions

View File

@@ -0,0 +1,23 @@
<!--
Adds an inline badge. The shortcode supports the following arguments:
"title" Required title of the badge.
"class" Optional class attributes of the badge element.
"color" Optional theme color of the element, either "primary", "secondary" (default), "success",
"danger", "warning", "info", "light", "dark", "white", or "black".
-->
{{- $error := false -}}
{{- $title := .Get "title" -}}
{{- $class := .Get "class" -}}
{{- $color := "secondary" -}}
{{- with .Get "color" }}{{ $color = . }}{{ end -}}
{{- $supportedColors := slice "primary" "secondary" "success" "danger" "warning" "info" "light" "dark" "white" "black" -}}
{{- if not (in $supportedColors $color) -}}
{{- errorf "Invalid value for param 'color': %s" .Position -}}
{{- end -}}
{{- if not $title }}
{{ errorf "Missing title: %s" .Position -}}
{{ else -}}
<span class="badge bg-{{ $color }}{{ with $class }} {{ . }}{{ end }}">{{ $title | plainify }}</span>
{{ end -}}