From c8ee5fc6577b70bdaee85a277598d3bf1eb30e88 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sun, 31 Aug 2025 16:47:21 +0800 Subject: [PATCH] refactor(article-link): unify featured image rendering with MediaType check --- layouts/partials/article-link/_shortcode.html | 14 ++++---------- layouts/partials/article-link/card-related.html | 16 ++++------------ layouts/partials/article-link/card.html | 12 ++++-------- layouts/partials/article-link/simple.html | 14 ++++---------- 4 files changed, 16 insertions(+), 40 deletions(-) diff --git a/layouts/partials/article-link/_shortcode.html b/layouts/partials/article-link/_shortcode.html index d22e07d6..3d13844b 100644 --- a/layouts/partials/article-link/_shortcode.html +++ b/layouts/partials/article-link/_shortcode.html @@ -48,18 +48,12 @@ {{ end }} {{ if $target.Params.hideFeatureImage }}{{ $featured = false }}{{ end }} {{ with $featured }} - {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} - {{ with . }} -
- {{ end }} - {{ else }} - {{ with .Resize "600x" }} -
- {{ end }} + {{ $featuredURL := .RelPermalink }} + {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} + {{ $featuredURL = (.Resize "600x").RelPermalink }} {{ end }} +
{{ end }} - -
{{ with $target.Params.externalUrl }} diff --git a/layouts/partials/article-link/card-related.html b/layouts/partials/article-link/card-related.html index 5c04e221..9e5254b4 100644 --- a/layouts/partials/article-link/card-related.html +++ b/layouts/partials/article-link/card-related.html @@ -17,19 +17,11 @@ {{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} {{ end }} {{ with $featured }} - {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} - {{ with . }} - - {{ end }} - {{ else }} - {{ with .Resize "600x" }} - - {{ end }} + {{ $featuredURL := .RelPermalink }} + {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} + {{ $featuredURL = (.Resize "600x").RelPermalink }} {{ end }} + {{ end }} {{ if and .Draft .Site.Params.article.showDraftLabel }} diff --git a/layouts/partials/article-link/card.html b/layouts/partials/article-link/card.html index cbce15df..df347f35 100644 --- a/layouts/partials/article-link/card.html +++ b/layouts/partials/article-link/card.html @@ -18,15 +18,11 @@ {{ end }} {{ if .Params.hideFeatureImage }}{{ $featured = false }}{{ end }} {{ with $featured }} - {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} - {{ with . }} -
- {{ end }} - {{ else }} - {{ with .Resize "600x" }} -
- {{ end }} + {{ $featuredURL := .RelPermalink }} + {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} + {{ $featuredURL = (.Resize "600x").RelPermalink }} {{ end }} +
{{ end }} {{ if and .Draft .Site.Params.article.showDraftLabel }} diff --git a/layouts/partials/article-link/simple.html b/layouts/partials/article-link/simple.html index c7e10e4f..7d819dc0 100644 --- a/layouts/partials/article-link/simple.html +++ b/layouts/partials/article-link/simple.html @@ -46,18 +46,12 @@ {{ end }} {{ if .Params.hideFeatureImage }}{{ $featured = false }}{{ end }} {{ with $featured }} - {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} - {{ with . }} -
- {{ end }} - {{ else }} - {{ with .Resize "600x" }} -
- {{ end }} + {{ $featuredURL := .RelPermalink }} + {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} + {{ $featuredURL = (.Resize "600x").RelPermalink }} {{ end }} +
{{ end }} - -
{{ with .Params.externalUrl }}