From 57befe227fc98123c00647fd0465f287398b1a6f Mon Sep 17 00:00:00 2001 From: rxchi1d Date: Mon, 22 Dec 2025 14:18:31 +0800 Subject: [PATCH] feat(admonitions): add header-only support --- assets/css/compiled/main.css | 5 +++ .../_default/_markup/render-blockquote.html | 35 +++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/assets/css/compiled/main.css b/assets/css/compiled/main.css index f702bc11..5f13bc41 100644 --- a/assets/css/compiled/main.css +++ b/assets/css/compiled/main.css @@ -1452,6 +1452,11 @@ .self-center { align-self: center; } + .truncate { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } .\!overflow-hidden { overflow: hidden !important; } diff --git a/layouts/_default/_markup/render-blockquote.html b/layouts/_default/_markup/render-blockquote.html index 494be44f..627a4ca9 100644 --- a/layouts/_default/_markup/render-blockquote.html +++ b/layouts/_default/_markup/render-blockquote.html @@ -35,13 +35,32 @@ {{- $rawType := .AlertType | lower -}} {{- $normalizedType := index $typeMap $rawType | default $rawType -}} {{- $iconName := index $iconMap $normalizedType | default "circle-info" -}} - {{- $title := .AlertTitle | default (i18n (printf "admonition.%s" $normalizedType) | default (title $normalizedType)) -}} + {{- $contentText := .Text | plainify | strings.TrimSpace -}} + {{- $hasContent := ne $contentText "" -}} + {{- $isHeaderOnly := not $hasContent -}} + + {{- $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 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" -}} + {{- 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 := in (slice "+" "-") .AlertSign -}} + {{- $isCollapsible := and $hasContent (in (slice "+" "-") .AlertSign) -}} {{- if $isCollapsible -}}
-
- {{- .Text | safeHTML -}} -
+ {{- if $hasContent -}} +
+ {{- .Text | safeHTML -}} +
+ {{- end -}} {{- end -}}