From 0317f3aa0e2369388d6b4e972e607f28a1d78f43 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Mon, 22 Dec 2025 12:29:12 +0800 Subject: [PATCH] refactor(admonition): simplify code --- .../_default/_markup/render-blockquote.html | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/layouts/_default/_markup/render-blockquote.html b/layouts/_default/_markup/render-blockquote.html index 6a5a0bdb..494be44f 100644 --- a/layouts/_default/_markup/render-blockquote.html +++ b/layouts/_default/_markup/render-blockquote.html @@ -1,4 +1,3 @@ -{{/* Admonition Render Hook */}} {{- if eq .Type "alert" -}} {{- $typeMap := dict "summary" "abstract" @@ -33,38 +32,21 @@ "quote" "quote-left" -}} - {{/* Resolve type aliases and validate */}} {{- $rawType := .AlertType | lower -}} {{- $normalizedType := index $typeMap $rawType | default $rawType -}} - {{- $iconName := index $iconMap $normalizedType | default "circle-info" -}} - - {{/* Resolve title with i18n fallback */}} - {{- $title := .AlertTitle -}} - {{- if not $title -}} - {{- $i18nKey := printf "admonition.%s" $normalizedType -}} - {{- $i18nTitle := i18n $i18nKey -}} - {{- if and $i18nTitle (ne $i18nTitle $i18nKey) -}} - {{- $title = $i18nTitle -}} - {{- else -}} - {{- $title = $normalizedType | title -}} - {{- end -}} - {{- end -}} - - {{/* Handle collapsible state */}} - {{- $sign := .AlertSign | default "" -}} - {{- $isCollapsible := or (eq $sign "+") (eq $sign "-") -}} - {{- $isDefaultCollapsed := eq $sign "-" -}} + {{- $title := .AlertTitle | default (i18n (printf "admonition.%s" $normalizedType) | default (title $normalizedType)) -}} {{- $containerClass := "admonition relative overflow-hidden rounded-lg border-l-4 px-4 py-3 shadow-sm print:break-inside-avoid" -}} {{- $headerClass := "flex items-center gap-2 font-semibold text-inherit" -}} {{- $contentClass := "admonition-content mt-3 text-base leading-relaxed text-inherit" -}} + {{- $isCollapsible := in (slice "+" "-") .AlertSign -}} {{- if $isCollapsible -}}
+ {{ if eq .AlertSign "+" }}open{{ end }}>