mirror of
https://github.com/nunocoracao/blowfish.git
synced 2026-01-30 16:31:52 +01:00
feat(admonition): polish
- sort by type names - tweak colors of some types - improve dark mode contrast - prune css - simplify render hook
This commit is contained in:
@@ -1,101 +1,81 @@
|
||||
{{- if eq .Type "alert" -}}
|
||||
{{- $typeMap := dict
|
||||
"attention" "warning"
|
||||
"check" "success"
|
||||
"cite" "quote"
|
||||
"done" "success"
|
||||
"error" "danger"
|
||||
"fail" "failure"
|
||||
"faq" "question"
|
||||
"hint" "tip"
|
||||
"help" "question"
|
||||
"missing" "failure"
|
||||
"summary" "abstract"
|
||||
"tldr" "abstract"
|
||||
"hint" "tip"
|
||||
"check" "success"
|
||||
"done" "success"
|
||||
"help" "question"
|
||||
"faq" "question"
|
||||
"attention" "warning"
|
||||
"fail" "failure"
|
||||
"missing" "failure"
|
||||
"error" "danger"
|
||||
"cite" "quote"
|
||||
-}}
|
||||
|
||||
{{- $iconMap := dict
|
||||
"note" "circle-info"
|
||||
"abstract" "file-lines"
|
||||
"bug" "bug"
|
||||
"caution" "fire"
|
||||
"danger" "fire"
|
||||
"example" "list-ol"
|
||||
"failure" "xmark"
|
||||
"important" "star"
|
||||
"info" "circle-info"
|
||||
"note" "circle-info"
|
||||
"success" "check"
|
||||
"todo" "list-check"
|
||||
"tip" "lightbulb"
|
||||
"important" "star"
|
||||
"success" "check"
|
||||
"question" "circle-question"
|
||||
"warning" "triangle-exclamation"
|
||||
"caution" "triangle-exclamation"
|
||||
"failure" "xmark"
|
||||
"danger" "fire"
|
||||
"bug" "bug"
|
||||
"example" "list-ol"
|
||||
"quote" "quote-left"
|
||||
"warning" "triangle-exclamation"
|
||||
-}}
|
||||
|
||||
{{- $rawType := .AlertType | lower -}}
|
||||
{{- $normalizedType := index $typeMap $rawType | default $rawType -}}
|
||||
{{- $iconName := index $iconMap $normalizedType | default "circle-info" -}}
|
||||
{{- $contentText := .Text | plainify | strings.TrimSpace -}}
|
||||
{{- $hasContent := ne $contentText "" -}}
|
||||
{{- $isHeaderOnly := not $hasContent -}}
|
||||
{{- $admonitionTitle := .AlertTitle | default (i18n (printf "admonition.%s" $normalizedType) | default $normalizedType) -}}
|
||||
|
||||
{{- $title := .AlertTitle -}}
|
||||
{{- if not $title -}}
|
||||
{{- $i18nKey := printf "admonition.%s" $normalizedType -}}
|
||||
{{- $i18nTitle := i18n $i18nKey -}}
|
||||
{{- if and $i18nTitle (ne $i18nTitle $i18nKey) -}}
|
||||
{{- $title = $i18nTitle -}}
|
||||
{{- else -}}
|
||||
{{- $title = title $normalizedType -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $containerClass := "admonition relative overflow-hidden rounded-lg border-l-4 my-3 px-4 py-3 shadow-sm" -}}
|
||||
{{- $headerClass := "flex items-center gap-2 font-semibold text-inherit capitalize" -}}
|
||||
{{- $contentClass := "admonition-content mt-3 text-base leading-relaxed text-inherit" -}}
|
||||
|
||||
{{- $containerClass := "admonition relative overflow-hidden rounded-lg border-l-4 px-4 py-3 shadow-sm print:break-inside-avoid" -}}
|
||||
{{- if $isHeaderOnly -}}
|
||||
{{- $containerClass = printf "%s admonition--header-only" $containerClass -}}
|
||||
{{- end -}}
|
||||
{{- $headerClass := "admonition-header flex items-center gap-2 font-semibold text-inherit" -}}
|
||||
{{- $contentClass := "admonition-content text-base leading-relaxed text-inherit" -}}
|
||||
{{- if $hasContent -}}
|
||||
{{- $contentClass = printf "%s mt-3" $contentClass -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $isCollapsible := and $hasContent (in (slice "+" "-") .AlertSign) -}}
|
||||
{{- $isCollapsible := in (slice "+" "-") .AlertSign -}}
|
||||
{{- if $isCollapsible -}}
|
||||
<details
|
||||
class="{{ $containerClass }} group print:block"
|
||||
class="{{ $containerClass }} group"
|
||||
data-type="{{ $normalizedType }}"
|
||||
{{ if eq .AlertSign "+" }}open{{ end }}>
|
||||
<summary
|
||||
class="{{ $headerClass }} cursor-pointer pr-2 list-none marker:hidden [&::-webkit-details-marker]:hidden">
|
||||
<div class="flex h-5 w-5 shrink-0 items-center justify-center text-current">
|
||||
<summary class="{{ $headerClass }} cursor-pointer">
|
||||
<div class="flex shrink-0 h-5 w-5 items-center justify-center text-lg">
|
||||
{{- partial "icon.html" $iconName -}}
|
||||
</div>
|
||||
<div class="flex grow items-center leading-snug">
|
||||
{{ $title }}
|
||||
<div class="grow">
|
||||
{{ $admonitionTitle }}
|
||||
</div>
|
||||
<div
|
||||
class="ml-auto flex h-6 w-6 items-center justify-center rounded-md text-current transition-transform ease-in-out -rotate-90 group-open:rotate-0 print:hidden">
|
||||
<div class="h-4 w-4">
|
||||
{{- partial "icon.html" "chevron-down" -}}
|
||||
</div>
|
||||
class="ms-auto flex h-5 w-5 items-center justify-center transition-transform ease-in-out -rotate-90 group-open:rotate-0 print:hidden">
|
||||
{{- partial "icon.html" "chevron-down" -}}
|
||||
</div>
|
||||
</summary>
|
||||
<div class="{{ $contentClass }}">
|
||||
{{- .Text | safeHTML -}}
|
||||
</div>
|
||||
{{- if .Text -}}
|
||||
<div class="{{ $contentClass }}">
|
||||
{{- .Text | safeHTML -}}
|
||||
</div>
|
||||
{{- end -}}
|
||||
</details>
|
||||
{{- else -}}
|
||||
<div class="{{ $containerClass }}" data-type="{{ $normalizedType }}">
|
||||
<div class="{{ $headerClass }}">
|
||||
<div class="flex h-5 w-5 shrink-0 items-center justify-center text-current">
|
||||
<div class="flex shrink-0 h-5 w-5 items-center justify-center text-lg">
|
||||
{{- partial "icon.html" $iconName -}}
|
||||
</div>
|
||||
<div class="flex grow items-center leading-snug">
|
||||
{{ $title }}
|
||||
<div class="grow">
|
||||
{{ $admonitionTitle }}
|
||||
</div>
|
||||
</div>
|
||||
{{- if $hasContent -}}
|
||||
{{- if .Text -}}
|
||||
<div class="{{ $contentClass }}">
|
||||
{{- .Text | safeHTML -}}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user