From 24fb13b221da34512fda402ff9fe7590a6f358c7 Mon Sep 17 00:00:00 2001 From: Xin Date: Sun, 31 Mar 2024 12:06:47 +0200 Subject: [PATCH] refactor: extract card shortcode to partial (#339) * refactor: extract card shortcode to partial * chore: update hugo stats --- exampleSite/hugo_stats.json | 3 ++ layouts/partials/shortcodes/card.html | 54 +++++++++++++++++++++++++++ layouts/shortcodes/card.html | 54 ++++++--------------------- 3 files changed, 69 insertions(+), 42 deletions(-) create mode 100644 layouts/partials/shortcodes/card.html diff --git a/exampleSite/hugo_stats.json b/exampleSite/hugo_stats.json index 8bc25bbb..734f8d09 100644 --- a/exampleSite/hugo_stats.json +++ b/exampleSite/hugo_stats.json @@ -208,6 +208,9 @@ "group-open:before:hx-rotate-90", "hamburger-menu", "hextra-card", + "hextra-card-icon", + "hextra-card-image", + "hextra-card-subtitle", "hextra-cards", "hextra-code-block", "hextra-code-copy-btn", diff --git a/layouts/partials/shortcodes/card.html b/layouts/partials/shortcodes/card.html new file mode 100644 index 00000000..b55c323b --- /dev/null +++ b/layouts/partials/shortcodes/card.html @@ -0,0 +1,54 @@ +{{- $page := .page -}} +{{- $link := .link -}} +{{- $title := .title -}} +{{- $icon := .icon -}} +{{- $subtitle := .subtitle -}} +{{- $image := .image -}} +{{- $width := .width -}} +{{- $height := .height -}} +{{- $imageStyle := .imageStyle -}} + +{{ $linkClass := "hover:hx-border-gray-300 hx-bg-transparent hx-shadow-sm dark:hx-border-neutral-800 hover:hx-bg-slate-50 hover:hx-shadow-md dark:hover:hx-border-neutral-700 dark:hover:hx-bg-neutral-900" }} +{{- with $image -}} + {{ $linkClass = "hover:hx-border-gray-300 hx-bg-gray-100 hx-shadow dark:hx-border-neutral-700 dark:hx-bg-neutral-800 dark:hx-text-gray-50 hover:hx-shadow-lg dark:hover:hx-border-neutral-500 dark:hover:hx-bg-neutral-700" }} +{{- end -}} + +{{- $external := strings.HasPrefix $link "http" -}} +{{- $href := cond (strings.HasPrefix $link "/") ($link | relURL) $link -}} + + + + {{- with $image -}} + {{ $title }} + {{- end -}} + + {{- $padding := "hx-p-4" -}} + {{- with $subtitle -}} + {{- $padding = "hx-pt-4 hx-px-4" -}} + {{- end -}} + + + + {{- with $icon }}{{ partial "utils/icon.html" (dict "name" $icon) -}}{{- end -}} + {{- $title -}} + + {{- with $subtitle -}} +
{{- $subtitle | markdownify -}}
+ {{- end -}} +
+{{- /* Strip trailing newline. */ -}} diff --git a/layouts/shortcodes/card.html b/layouts/shortcodes/card.html index d47d6088..712ab02c 100644 --- a/layouts/shortcodes/card.html +++ b/layouts/shortcodes/card.html @@ -38,45 +38,15 @@ {{- end -}} {{- end -}} -{{ $linkClass := "hover:hx-border-gray-300 hx-bg-transparent hx-shadow-sm dark:hx-border-neutral-800 hover:hx-bg-slate-50 hover:hx-shadow-md dark:hover:hx-border-neutral-700 dark:hover:hx-bg-neutral-900" }} -{{- with $image -}} - {{ $linkClass = "hover:hx-border-gray-300 hx-bg-gray-100 hx-shadow dark:hx-border-neutral-700 dark:hx-bg-neutral-800 dark:hx-text-gray-50 hover:hx-shadow-lg dark:hover:hx-border-neutral-500 dark:hover:hx-bg-neutral-700" }} -{{- end -}} - -{{- $external := strings.HasPrefix $link "http" -}} -{{- $href := cond (strings.HasPrefix $link "/") ($link | relURL) $link -}} - - - - {{- with $image -}} - {{ $title }} - {{- end -}} - - {{- $padding := "hx-p-4" -}} - {{- with $subtitle -}} - {{- $padding = "hx-pt-4 hx-px-4" -}} - {{- end -}} - - - - {{- with $icon }}{{ partial "utils/icon.html" (dict "name" $icon) -}}{{- end -}} - {{- $title -}} - - {{- with $subtitle -}} -
{{- $subtitle | markdownify -}}
- {{- end -}} -
-{{- /* Strip trailing newline. */ -}} +{{- partial "shortcodes/card" (dict + "page" .Page + "link" $link + "title" $title + "icon" $icon + "subtitle" $subtitle + "image" $image + "width" $width + "height" $height + "imageStyle" $imageStyle + ) +-}}