mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
38 lines
1.2 KiB
HTML
38 lines
1.2 KiB
HTML
{{- /*
|
|
* The basic syntax of alert is compatible with GitHub, Obsidian, and Typora.
|
|
* @param {String} .Type the type of the alert box
|
|
* @param {String} .Text the content of the alert box
|
|
* @param {Map} [.Attributes] the attributes of the alert box
|
|
* @example {{- dict "Text" .Text "Type" .AlertType "Attributes" .Attributes | partial "plugin/alert.html" -}}
|
|
*/ -}}
|
|
|
|
{{- $iconMap := dict
|
|
"note" "images/icons/alerts/info.svg"
|
|
"tip" "images/icons/alerts/light-bulb.svg"
|
|
"important" "images/icons/alerts/report.svg"
|
|
"warning" "images/icons/alerts/alert.svg"
|
|
"caution" "images/icons/alerts/stop.svg"
|
|
-}}
|
|
|
|
{{- $attrs := "" }}
|
|
{{- range $key, $value := .Attributes }}
|
|
{{- $attrs = printf "%s %s=%q" $attrs $key $value }}
|
|
{{- end }}
|
|
|
|
{{- with .Attributes.class }}
|
|
{{- $attrs = replace $attrs . (printf "alert alert-%s %s" $.Type .) }}
|
|
{{- else }}
|
|
{{- $attrs = printf "class=%q %s" (printf "alert alert-%s" $.Type) $attrs }}
|
|
{{- end }}
|
|
{{- $attrs = trim $attrs " " -}}
|
|
|
|
<div {{ $attrs | safeHTMLAttr }}>
|
|
{{- $icon := index $iconMap .Type -}}
|
|
<p class="alert-title">
|
|
{{- dict "Src" $icon | partial "plugin/icon.html" }}
|
|
{{- or (T (printf "alert.%v" .Type)) (title .Type) -}}
|
|
</p>
|
|
{{- .Text | safeHTML -}}
|
|
</div>
|
|
{{- /* EOF */ -}}
|