From 35faec527b9f0dddd2a75f1db2cc4e7974079163 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Wed, 9 Jul 2025 23:39:03 +0800 Subject: [PATCH 1/3] refactor(article-link): abstract anchor attributes for making article links formattable --- layouts/partials/article-link/_external-link.html | 5 +++++ layouts/partials/article-link/card-related.html | 6 +----- layouts/partials/article-link/card.html | 6 +----- layouts/partials/article-link/simple.html | 6 +----- 4 files changed, 8 insertions(+), 15 deletions(-) create mode 100644 layouts/partials/article-link/_external-link.html diff --git a/layouts/partials/article-link/_external-link.html b/layouts/partials/article-link/_external-link.html new file mode 100644 index 00000000..e3e9980d --- /dev/null +++ b/layouts/partials/article-link/_external-link.html @@ -0,0 +1,5 @@ +{{ with .Params.externalUrl }} + href="{{ . }}" target="_blank" rel="external" +{{ else }} + href="{{ .RelPermalink }}" +{{- end -}} diff --git a/layouts/partials/article-link/card-related.html b/layouts/partials/article-link/card-related.html index f576763a..41e89f8b 100644 --- a/layouts/partials/article-link/card-related.html +++ b/layouts/partials/article-link/card-related.html @@ -1,8 +1,4 @@ -{{ with .Params.externalUrl }} - - {{ else }} - - {{ end }} +
{{- with $.Params.images -}} diff --git a/layouts/partials/article-link/card.html b/layouts/partials/article-link/card.html index 0ce06e75..97390da8 100644 --- a/layouts/partials/article-link/card.html +++ b/layouts/partials/article-link/card.html @@ -1,8 +1,4 @@ -{{ with .Params.externalUrl }} - - {{ else }} - - {{ end }} +
{{- with $.Params.images -}} diff --git a/layouts/partials/article-link/simple.html b/layouts/partials/article-link/simple.html index e56a2afd..269b990b 100644 --- a/layouts/partials/article-link/simple.html +++ b/layouts/partials/article-link/simple.html @@ -26,11 +26,7 @@ {{ end }} -{{ with .Params.externalUrl }} - - {{ else }} - - {{ end }} + {{- with $.Params.images -}} {{- range first 6 . }} {{ end -}} From 297899521114e12420124abaa96bab07d47cd9f5 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Wed, 9 Jul 2025 23:43:26 +0800 Subject: [PATCH 2/3] style(article-link): run prettier format --- .prettierignore | 3 - .../partials/article-link/card-related.html | 91 +++++++------- layouts/partials/article-link/card.html | 98 +++++++-------- layouts/partials/article-link/simple.html | 112 +++++++++--------- 4 files changed, 155 insertions(+), 149 deletions(-) diff --git a/.prettierignore b/.prettierignore index c128736f..30e754c9 100644 --- a/.prettierignore +++ b/.prettierignore @@ -28,9 +28,6 @@ static layouts/_default/_markup/render-heading.html layouts/_default/index.json layouts/_default/list.html -layouts/partials/article-link/card-related.html -layouts/partials/article-link/card.html -layouts/partials/article-link/simple.html layouts/partials/hero/background.html layouts/shortcodes/screenshot.html layouts/shortcodes/figure.html diff --git a/layouts/partials/article-link/card-related.html b/layouts/partials/article-link/card-related.html index 41e89f8b..11045624 100644 --- a/layouts/partials/article-link/card-related.html +++ b/layouts/partials/article-link/card-related.html @@ -1,44 +1,45 @@ -
- - {{- with $.Params.images -}} +
+ {{- with $.Params.images -}} {{- range first 6 . }} - {{ end -}} - {{- else -}} - {{ $images := $.Resources.ByType "image" }} - {{ $featuredImage := $images.GetMatch "*feature*" }} - {{ if not $featuredImage }} - {{ $featuredImage = $images.GetMatch "{*cover*,*thumbnail*}" }} - {{ end }} - {{ if and (not $featuredImage) .Params.featureimage }} - {{ $featuredImage = resources.GetRemote .Params.featureimage }} - {{ end }} - {{ if not $featuredImage }} - {{ $featuredImage = resources.Get .Site.Params.defaultFeaturedImage }} - {{ end }} - {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} - {{ if and ($featuredImage) (not (or ($disableImageOptimization) (strings.HasSuffix $featuredImage.Name ".svg"))) }} - {{ $featuredImage = $featuredImage.Resize "600x" }} - {{ end }} - {{ with $featuredImage }} - {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} - - {{ else }} - {{ with $.Site.Params.images }} - + + {{ end -}} + {{- else -}} + {{ $images := $.Resources.ByType "image" }} + {{ $featuredImage := $images.GetMatch "*feature*" }} + {{ if not $featuredImage }} + {{ $featuredImage = $images.GetMatch "{*cover*,*thumbnail*}" }} + {{ end }} + {{ if and (not $featuredImage) .Params.featureimage }} + {{ $featuredImage = resources.GetRemote .Params.featureimage }} + {{ end }} + {{ if not $featuredImage }} + {{ $featuredImage = resources.Get .Site.Params.defaultFeaturedImage }} + {{ end }} + {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} + {{ if and ($featuredImage) (not (or ($disableImageOptimization) (strings.HasSuffix $featuredImage.Name ".svg"))) }} + {{ $featuredImage = $featuredImage.Resize "600x" }} + {{ end }} + {{ with $featuredImage }} + {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} + + {{ else }} + {{ with $.Site.Params.images }} + {{ end }} {{ end }} {{ end }} - {{ if and .Draft .Site.Params.article.showDraftLabel }} + {{ if and .Draft .Site.Params.article.showDraftLabel }} {{ partial "badge.html" (i18n "article.draft" | emojify) }} - {{ end }} + {{ end }} - + diff --git a/layouts/partials/article-link/card.html b/layouts/partials/article-link/card.html index 97390da8..70affad0 100644 --- a/layouts/partials/article-link/card.html +++ b/layouts/partials/article-link/card.html @@ -1,48 +1,48 @@ -
- - {{- with $.Params.images -}} +
+ {{- with $.Params.images -}} {{- range first 6 . }} - {{ end -}} - {{- else -}} - {{ $images := $.Resources.ByType "image" }} - {{ $featuredImage := $images.GetMatch "*feature*" }} - {{ if not $featuredImage }} - {{ $featuredImage = $images.GetMatch "{*cover*,*thumbnail*}" }} - {{ end }} - {{ if and (not $featuredImage) .Params.featureimage }} - {{ $featuredImage = resources.GetRemote .Params.featureimage }} - {{ end }} - {{ if not $featuredImage }} - {{ $featuredImage = resources.Get .Site.Params.defaultFeaturedImage }} - {{ end }} - {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} - {{ if and ($featuredImage) (not (or ($disableImageOptimization) (strings.HasSuffix $featuredImage.Name ".svg"))) }} - {{ $featuredImage = $featuredImage.Resize "600x" }} - {{ end }} - {{ if .Params.hideFeatureImage }} - {{ $featuredImage = false }} - {{ end }} - {{ with $featuredImage }} - {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} -
- {{ else }} - {{ with $.Site.Params.images }} - + + {{ end -}} + {{- else -}} + {{ $images := $.Resources.ByType "image" }} + {{ $featuredImage := $images.GetMatch "*feature*" }} + {{ if not $featuredImage }} + {{ $featuredImage = $images.GetMatch "{*cover*,*thumbnail*}" }} + {{ end }} + {{ if and (not $featuredImage) .Params.featureimage }} + {{ $featuredImage = resources.GetRemote .Params.featureimage }} + {{ end }} + {{ if not $featuredImage }} + {{ $featuredImage = resources.Get .Site.Params.defaultFeaturedImage }} + {{ end }} + {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} + {{ if and ($featuredImage) (not (or ($disableImageOptimization) (strings.HasSuffix $featuredImage.Name ".svg"))) }} + {{ $featuredImage = $featuredImage.Resize "600x" }} + {{ end }} + {{ if .Params.hideFeatureImage }} + {{ $featuredImage = false }} + {{ end }} + {{ with $featuredImage }} + {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} +
+ {{ else }} + {{ with $.Site.Params.images }} + {{ end }} {{ end }} {{ end }} - - {{ if and .Draft .Site.Params.article.showDraftLabel }} + {{ if and .Draft .Site.Params.article.showDraftLabel }} {{ partial "badge.html" (i18n "article.draft" | emojify) }} - {{ end }} + {{ end }} -
+ diff --git a/layouts/partials/article-link/simple.html b/layouts/partials/article-link/simple.html index 269b990b..9f0ab86d 100644 --- a/layouts/partials/article-link/simple.html +++ b/layouts/partials/article-link/simple.html @@ -2,67 +2,68 @@ {{ $articleClasses := "flex flex-wrap md:flex-nowrap article" }} {{ if .Site.Params.list.showCards }} -{{ $articleClasses = delimit (slice $articleClasses "border border-neutral-200 dark:border-neutral-700 border-2 rounded-md overflow-hidden") " " }} + {{ $articleClasses = delimit (slice $articleClasses "border border-neutral-200 dark:border-neutral-700 border-2 rounded-md overflow-hidden") " " }} {{ else }} -{{ $articleClasses = delimit (slice $articleClasses "") " " }} + {{ $articleClasses = delimit (slice $articleClasses "") " " }} {{ end }} {{ $articleImageClasses := "w-full md:w-auto h-full thumbnail nozoom" }} {{ if .Site.Params.list.showCards }} -{{ $articleImageClasses = delimit (slice $articleImageClasses "") " " }} + {{ $articleImageClasses = delimit (slice $articleImageClasses "") " " }} {{ else }} -{{ $articleImageClasses = delimit (slice $articleImageClasses "thumbnailshadow md:mr-7") " " }} + {{ $articleImageClasses = delimit (slice $articleImageClasses "thumbnailshadow md:mr-7") " " }} {{ end }} {{ $articleInnerClasses := "" }} {{ if .Site.Params.list.showCards }} -{{ $articleInnerClasses = delimit (slice $articleInnerClasses "p-4") " " }} + {{ $articleInnerClasses = delimit (slice $articleInnerClasses "p-4") " " }} {{ else }} -{{ $articleInnerClasses = delimit (slice $articleInnerClasses "mt-3 md:mt-0") " " }} + {{ $articleInnerClasses = delimit (slice $articleInnerClasses "mt-3 md:mt-0") " " }} {{ end }} {{ if $constrainItemsWidth }} -{{ $articleClasses = delimit (slice $articleClasses "max-w-prose") " " }} + {{ $articleClasses = delimit (slice $articleClasses "max-w-prose") " " }} {{ end }} - {{- with $.Params.images -}} + {{- with $.Params.images -}} {{- range first 6 . }} - {{ end -}} - {{- else -}} - {{ $images := $.Resources.ByType "image" }} - {{ $featuredImage := $images.GetMatch "*feature*" }} - {{ if not $featuredImage }} - {{ $featuredImage = $images.GetMatch "{*cover*,*thumbnail*}" }} - {{ end }} - {{ if and (not $featuredImage) .Params.featureimage }} - {{ $featuredImage = resources.GetRemote .Params.featureimage }} - {{ end }} - {{ if not $featuredImage }} - {{ $featuredImage = resources.Get .Site.Params.defaultFeaturedImage }} - {{ end }} - {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} - {{ if and ($featuredImage) (not (or ($disableImageOptimization) (strings.HasSuffix $featuredImage.Name ".svg"))) }} - {{ $featuredImage = $featuredImage.Resize "600x" }} - {{ end }} - {{ if .Params.hideFeatureImage }} - {{ $featuredImage = false }} - {{ end }} - {{ with $featuredImage }} - {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} -
- {{ else }} - {{ with $.Site.Params.images }} - - {{ end }} + + {{ end -}} + {{- else -}} + {{ $images := $.Resources.ByType "image" }} + {{ $featuredImage := $images.GetMatch "*feature*" }} + {{ if not $featuredImage }} + {{ $featuredImage = $images.GetMatch "{*cover*,*thumbnail*}" }} + {{ end }} + {{ if and (not $featuredImage) .Params.featureimage }} + {{ $featuredImage = resources.GetRemote .Params.featureimage }} + {{ end }} + {{ if not $featuredImage }} + {{ $featuredImage = resources.Get .Site.Params.defaultFeaturedImage }} + {{ end }} + {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} + {{ if and ($featuredImage) (not (or ($disableImageOptimization) (strings.HasSuffix $featuredImage.Name ".svg"))) }} + {{ $featuredImage = $featuredImage.Resize "600x" }} + {{ end }} + {{ if .Params.hideFeatureImage }} + {{ $featuredImage = false }} + {{ end }} + {{ with $featuredImage }} + {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} +
+ {{ else }} + {{ with $.Site.Params.images }} + {{ end }} {{ end }} + {{ end }} -
+ From 78f5910f0e8724d54b01d745523437e155045fb9 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Thu, 10 Jul 2025 00:04:15 +0800 Subject: [PATCH 3/3] chore: update .prettierignore --- .prettierignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.prettierignore b/.prettierignore index 30e754c9..0a829920 100644 --- a/.prettierignore +++ b/.prettierignore @@ -28,8 +28,8 @@ static layouts/_default/_markup/render-heading.html layouts/_default/index.json layouts/_default/list.html -layouts/partials/hero/background.html layouts/shortcodes/screenshot.html layouts/shortcodes/figure.html +layouts/partials/hugo-embedded/shortcodes/figure-default.html assets/js/appearance.js