From 672179fe703ab87d71ca6d174b78c02f8a761002 Mon Sep 17 00:00:00 2001 From: Xin Date: Sat, 14 Dec 2024 17:27:33 +0000 Subject: [PATCH] feat: basic github style alerts support --- .../_markup/render-blockquote-alert.html | 20 ++++++++ .../_markup/render-blockquote-regular.html | 3 ++ layouts/partials/shortcodes/callout.html | 28 +++++++++++ layouts/shortcodes/callout.html | 46 ++++++------------- 4 files changed, 65 insertions(+), 32 deletions(-) create mode 100644 layouts/_default/_markup/render-blockquote-alert.html create mode 100644 layouts/_default/_markup/render-blockquote-regular.html create mode 100644 layouts/partials/shortcodes/callout.html diff --git a/layouts/_default/_markup/render-blockquote-alert.html b/layouts/_default/_markup/render-blockquote-alert.html new file mode 100644 index 0000000..b8dc8a4 --- /dev/null +++ b/layouts/_default/_markup/render-blockquote-alert.html @@ -0,0 +1,20 @@ +{{- $supportedAlertTypes := slice "note" "tip" "important" "warning" "caution" -}} +{{- $emojis := dict + "note" ":memo:" + "tip" ":bulb:" + "important" ":information_source:" + "warning" ":warning:" + "caution" ":exclamation:" +-}} + +{{- if not (in $supportedAlertTypes .AlertType) -}} +
+ {{- .Text -}} +
+{{- else -}} + {{- $emoji := emojify (index $emojis .AlertType) -}} + {{- $content := .Text -}} + {{- $icon := "" -}} + {{- $class := "" -}} + {{- partial "shortcodes/callout.html" (dict "content" $content "emoji" $emoji "icon" $icon "class" $class) -}} +{{- end -}} diff --git a/layouts/_default/_markup/render-blockquote-regular.html b/layouts/_default/_markup/render-blockquote-regular.html new file mode 100644 index 0000000..652cb51 --- /dev/null +++ b/layouts/_default/_markup/render-blockquote-regular.html @@ -0,0 +1,3 @@ +
+ {{ .Text }} +
diff --git a/layouts/partials/shortcodes/callout.html b/layouts/partials/shortcodes/callout.html new file mode 100644 index 0000000..417f631 --- /dev/null +++ b/layouts/partials/shortcodes/callout.html @@ -0,0 +1,28 @@ +{{- $content := .content -}} +{{- $emoji := .emoji -}} +{{- $icon := .icon -}} + +{{- $defaultClass := "hx-border-orange-100 hx-bg-orange-50 hx-text-orange-800 dark:hx-border-orange-400/30 dark:hx-bg-orange-400/20 dark:hx-text-orange-300" -}} + +{{- $class := .class | default $defaultClass -}} + + +
+
+ {{- with $emoji -}} +
+ {{- . -}} +
+ {{- else -}} + {{- with $icon -}} + {{ partial "utils/icon.html" (dict "name" . "attributes" `height=1.2em class="hx-inline-block hx-align-middle"`) -}} + {{- end -}} + {{- end -}} +
+ +
+
+ {{- $content -}} +
+
+
diff --git a/layouts/shortcodes/callout.html b/layouts/shortcodes/callout.html index 6b56bcb..9c9361a 100644 --- a/layouts/shortcodes/callout.html +++ b/layouts/shortcodes/callout.html @@ -1,37 +1,19 @@ -{{ $calloutEmojiDict := dict "info" "ℹ️" "warning" "⚠️" "error" "🚫" }} -{{ $type := .Get "type" | default "default" }} +{{- $calloutEmojiDict := dict "info" "ℹ️" "warning" "⚠️" "error" "🚫" -}} +{{- $type := .Get "type" | default "default" -}} {{/* If emoji is not set, use the emoji from dict */}} -{{ $emoji := .Get "emoji" }} -{{ if eq $emoji "" }} - {{ $emoji = index $calloutEmojiDict $type }} -{{ end }} +{{- $emoji := .Get "emoji" -}} +{{- if eq $emoji "" -}} + {{- $emoji = index $calloutEmojiDict $type -}} +{{- end -}} {{/* Also allow using "icon" */}} -{{ $icon := .Get "icon" }} +{{- $icon := .Get "icon" -}} +{{- $content := .InnerDeindent | markdownify -}} -{{ $defaultClass := "hx-border-orange-100 hx-bg-orange-50 hx-text-orange-800 dark:hx-border-orange-400/30 dark:hx-bg-orange-400/20 dark:hx-text-orange-300" }} -{{ $infoClass := "hx-border-blue-200 hx-bg-blue-100 hx-text-blue-900 dark:hx-border-blue-200/30 dark:hx-bg-blue-900/30 dark:hx-text-blue-200" }} -{{ $warningClass := "hx-border-yellow-100 hx-bg-yellow-50 hx-text-yellow-900 dark:hx-border-yellow-200/30 dark:hx-bg-yellow-700/30 dark:hx-text-yellow-200" }} -{{ $errorClass := "hx-border-red-200 hx-bg-red-100 hx-text-red-900 dark:hx-border-red-200/30 dark:hx-bg-red-900/30 dark:hx-text-red-200" }} +{{- $defaultClass := "hx-border-orange-100 hx-bg-orange-50 hx-text-orange-800 dark:hx-border-orange-400/30 dark:hx-bg-orange-400/20 dark:hx-text-orange-300" -}} +{{- $infoClass := "hx-border-blue-200 hx-bg-blue-100 hx-text-blue-900 dark:hx-border-blue-200/30 dark:hx-bg-blue-900/30 dark:hx-text-blue-200" -}} +{{- $warningClass := "hx-border-yellow-100 hx-bg-yellow-50 hx-text-yellow-900 dark:hx-border-yellow-200/30 dark:hx-bg-yellow-700/30 dark:hx-text-yellow-200" -}} +{{- $errorClass := "hx-border-red-200 hx-bg-red-100 hx-text-red-900 dark:hx-border-red-200/30 dark:hx-bg-red-900/30 dark:hx-text-red-200" -}} -{{ $class := cond (eq $type "info") $infoClass (cond (eq $type "warning") $warningClass (cond (eq $type "error") $errorClass $defaultClass)) }} +{{- $class := cond (eq $type "info") $infoClass (cond (eq $type "warning") $warningClass (cond (eq $type "error") $errorClass $defaultClass)) -}} - -
-
- {{- with $emoji -}} -
- {{ . }} -
- {{- else -}} - {{- with $icon }} - {{ partial "utils/icon.html" (dict "name" . "attributes" `height=1.2em class="hx-inline-block hx-align-middle"`) -}} - {{- end -}} - {{- end -}} -
- -
-
- {{ .InnerDeindent | markdownify }} -
-
-
+{{- partial "shortcodes/callout.html" (dict "content" $content "emoji" $emoji "icon" $icon "class" $class) -}}