refactor(admonition): simplify title handling logic

Replace complex title processing (9 lines) with single-line title filter approach.

Changes:
- Simplify $admonitionTitle definition from 5 variables to 1 line
- Remove $titleClass conditional logic (4 lines)
- Replace dynamic CSS class with static "grow" class
- Use Hugo title filter instead of CSS capitalize
- Remove TrimSpace processing per author feedback

This maintains the same visual behavior while significantly reducing code complexity.

Related: PR #2704 feedback from ZhenShuo2021
This commit is contained in:
rxchi1d
2026-01-04 23:25:28 +08:00
parent 966828efff
commit 17906e63e2

View File

@@ -33,19 +33,11 @@
{{- $normalizedType := index $typeMap $rawType | default $rawType -}}
{{- $iconName := .Attributes.icon | default (index $iconMap $normalizedType) | default "circle-info" -}}
{{- $rawCustomTitle := .AlertTitle | default "" -}}
{{- $trimmedCustomTitle := strings.TrimSpace $rawCustomTitle -}}
{{- $hasCustomTitle := ne $trimmedCustomTitle "" -}}
{{- $defaultTitle := i18n (printf "admonition.%s" $normalizedType) | default $normalizedType -}}
{{- $admonitionTitle := cond $hasCustomTitle $rawCustomTitle $defaultTitle -}}
{{- $admonitionTitle := .AlertTitle | default ((i18n (printf "admonition.%s" $normalizedType) | default $normalizedType) | title) -}}
{{- $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" -}}
{{- $contentClass := "admonition-content mt-3 text-base leading-relaxed text-inherit" -}}
{{- $titleClass := "grow" -}}
{{- if not $hasCustomTitle -}}
{{- $titleClass = printf "%s %s" $titleClass "capitalize" -}}
{{- end -}}
{{- $isCollapsible := in (slice "+" "-") .AlertSign -}}
{{- if $isCollapsible -}}
@@ -57,7 +49,7 @@
<div class="flex shrink-0 h-5 w-5 items-center justify-center text-lg">
{{- partial "icon.html" $iconName -}}
</div>
<div class="{{ $titleClass }}">
<div class="grow">
{{ $admonitionTitle }}
</div>
<div
@@ -77,7 +69,7 @@
<div class="flex shrink-0 h-5 w-5 items-center justify-center text-lg">
{{- partial "icon.html" $iconName -}}
</div>
<div class="{{ $titleClass }}">
<div class="grow">
{{ $admonitionTitle }}
</div>
</div>