From b2ff662c8e606b7986ece5c9ad23a9c2fe7a2a48 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Sun, 17 Aug 2025 19:44:02 +0200 Subject: [PATCH] chore: simplify style definition for badge and callout (#763) --- layouts/_partials/shortcodes/badge.html | 12 +++++++----- layouts/_shortcodes/callout.html | 10 ++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/layouts/_partials/shortcodes/badge.html b/layouts/_partials/shortcodes/badge.html index 43704e8..3777a3e 100644 --- a/layouts/_partials/shortcodes/badge.html +++ b/layouts/_partials/shortcodes/badge.html @@ -1,16 +1,18 @@ {{- $content := .content -}} -{{- $type := .type -}} +{{- $type := .type | default "" -}} {{- $class := .class | default "" -}} {{- $border := .border | default false -}} {{- $icon := .icon | default "" -}} {{- $defaultClass := "hx:text-gray-600 hx:bg-gray-100 hx:dark:bg-neutral-800 hx:dark:text-neutral-200 hx:border-gray-200 hx:dark:border-neutral-700" -}} -{{- $warningClass := "hx:border-yellow-100 hx:bg-yellow-50 hx:text-yellow-900 hx:dark:border-yellow-200/30 hx:dark:bg-yellow-700/30 hx:dark:text-yellow-200" -}} -{{- $infoClass := "hx:border-blue-200 hx:bg-blue-100 hx:text-blue-900 hx:dark:border-blue-200/30 hx:dark:bg-blue-900/30 hx:dark:text-blue-200" -}} -{{- $errorClass := "hx:border-red-200 hx:bg-red-100 hx:text-red-900 hx:dark:border-red-200/30 hx:dark:bg-red-900/30 hx:dark:text-red-200" -}} + +{{- $styleClass := newScratch -}} +{{- $styleClass.Set "info" "hx:border-blue-200 hx:bg-blue-100 hx:text-blue-900 hx:dark:border-blue-200/30 hx:dark:bg-blue-900/30 hx:dark:text-blue-200" -}} +{{- $styleClass.Set "warning" "hx:border-yellow-100 hx:bg-yellow-50 hx:text-yellow-900 hx:dark:border-yellow-200/30 hx:dark:bg-yellow-700/30 hx:dark:text-yellow-200" -}} +{{- $styleClass.Set "error" "hx:border-red-200 hx:bg-red-100 hx:text-red-900 hx:dark:border-red-200/30 hx:dark:bg-red-900/30 hx:dark:text-red-200" -}} {{- $borderClass := cond (eq $border true) "hx:border" "" -}} -{{- $badgeClass := cond (eq $type "info") $infoClass (cond (eq $type "warning") $warningClass (cond (eq $type "error") $errorClass $defaultClass)) -}} +{{- $badgeClass := or ($styleClass.Get $type) $defaultClass -}}
{{- with $icon -}}{{- partial "utils/icon" (dict "name" . "attributes" "height=12") -}}{{- end -}} diff --git a/layouts/_shortcodes/callout.html b/layouts/_shortcodes/callout.html index 5ccac93..f61a5fa 100644 --- a/layouts/_shortcodes/callout.html +++ b/layouts/_shortcodes/callout.html @@ -21,10 +21,12 @@ A shortcode to create a callout. {{- $content := .InnerDeindent | markdownify -}} {{- $defaultClass := "hx:border-orange-100 hx:bg-orange-50 hx:text-orange-800 hx:dark:border-orange-400/30 hx:dark:bg-orange-400/20 hx:dark:text-orange-300" -}} -{{- $infoClass := "hx:border-blue-200 hx:bg-blue-100 hx:text-blue-900 hx:dark:border-blue-200/30 hx:dark:bg-blue-900/30 hx:dark:text-blue-200" -}} -{{- $warningClass := "hx:border-yellow-100 hx:bg-yellow-50 hx:text-yellow-900 hx:dark:border-yellow-200/30 hx:dark:bg-yellow-700/30 hx:dark:text-yellow-200" -}} -{{- $errorClass := "hx:border-red-200 hx:bg-red-100 hx:text-red-900 hx:dark:border-red-200/30 hx:dark:bg-red-900/30 hx:dark:text-red-200" -}} -{{- $class := cond (eq $type "info") $infoClass (cond (eq $type "warning") $warningClass (cond (eq $type "error") $errorClass $defaultClass)) -}} +{{- $styleClass := newScratch -}} +{{- $styleClass.Set "info" "hx:border-blue-200 hx:bg-blue-100 hx:text-blue-900 hx:dark:border-blue-200/30 hx:dark:bg-blue-900/30 hx:dark:text-blue-200" -}} +{{- $styleClass.Set "warning" "hx:border-yellow-100 hx:bg-yellow-50 hx:text-yellow-900 hx:dark:border-yellow-200/30 hx:dark:bg-yellow-700/30 hx:dark:text-yellow-200" -}} +{{- $styleClass.Set "error" "hx:border-red-200 hx:bg-red-100 hx:text-red-900 hx:dark:border-red-200/30 hx:dark:bg-red-900/30 hx:dark:text-red-200" -}} + +{{- $class := or ($styleClass.Get $type) $defaultClass -}} {{- partial "shortcodes/callout.html" (dict "content" $content "emoji" $emoji "icon" $icon "class" $class) -}}