From 6d6b5d3946ecd740909ce5c76de94f779e25c32a Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sun, 31 Aug 2025 17:20:42 +0800 Subject: [PATCH] fix(article-link): skip fetching images when hideFeatureImage is true --- layouts/partials/article-link/_shortcode.html | 33 ++++++++++--------- .../partials/article-link/card-related.html | 4 +-- layouts/partials/article-link/card.html | 33 ++++++++++--------- layouts/partials/article-link/simple.html | 33 ++++++++++--------- 4 files changed, 53 insertions(+), 50 deletions(-) diff --git a/layouts/partials/article-link/_shortcode.html b/layouts/partials/article-link/_shortcode.html index 8c49b4a2..b154d594 100644 --- a/layouts/partials/article-link/_shortcode.html +++ b/layouts/partials/article-link/_shortcode.html @@ -32,24 +32,25 @@ {{ $articleClasses = delimit (slice $articleClasses "max-w-prose") " " }} {{ end }} -{{ $images := $target.Resources.ByType "image" }} {{ $featured := "" }} {{ $featuredURL := "" }} -{{ range slice "*feature*" "*cover*" "*thumbnail*" }} - {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} -{{ end }} -{{ if and $target.Params.featureimage (not $featured) }} - {{ $url:= $target.Params.featureimage }} - {{ $featured = resources.GetRemote $url }} -{{ end }} -{{ if not $featured }} - {{ with site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} -{{ end }} -{{ if $target.Params.hideFeatureImage }}{{ $featured = false }}{{ end }} -{{ with $featured }} - {{ $featuredURL = .RelPermalink }} - {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} - {{ $featuredURL = (.Resize "600x").RelPermalink }} +{{ if not .Params.hideFeatureImage }} + {{ $images := $target.Resources.ByType "image" }} + {{ range slice "*feature*" "*cover*" "*thumbnail*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} + {{ end }} + {{ if and $target.Params.featureimage (not $featured) }} + {{ $url:= $target.Params.featureimage }} + {{ $featured = resources.GetRemote $url }} + {{ end }} + {{ if not $featured }} + {{ with site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} + {{ end }} + {{ with $featured }} + {{ $featuredURL = .RelPermalink }} + {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} + {{ $featuredURL = (.Resize "600x").RelPermalink }} + {{ end }} {{ end }} {{ end }} diff --git a/layouts/partials/article-link/card-related.html b/layouts/partials/article-link/card-related.html index 52534210..2a933a3b 100644 --- a/layouts/partials/article-link/card-related.html +++ b/layouts/partials/article-link/card-related.html @@ -3,9 +3,9 @@ */}} {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} -{{ $images := $.Resources.ByType "image" }} {{ $featured := "" }} {{ $featuredURL := "" }} +{{ $images := $.Resources.ByType "image" }} {{ range slice "*feature*" "*cover*" "*thumbnail*" }} {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} {{ end }} @@ -14,7 +14,7 @@ {{ $featured = resources.GetRemote $url }} {{ end }} {{ if not $featured }} - {{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} + {{ with site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} {{ end }} {{ with $featured }} {{ $featuredURL = .RelPermalink }} diff --git a/layouts/partials/article-link/card.html b/layouts/partials/article-link/card.html index 29e923c1..5a9c4aa1 100644 --- a/layouts/partials/article-link/card.html +++ b/layouts/partials/article-link/card.html @@ -5,24 +5,25 @@ */}} {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} -{{ $images := $.Resources.ByType "image" }} {{ $featured := "" }} {{ $featuredURL := "" }} -{{ range slice "*feature*" "*cover*" "*thumbnail*" }} - {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} -{{ end }} -{{ if and .Params.featureimage (not $featured) }} - {{ $url:= .Params.featureimage }} - {{ $featured = resources.GetRemote $url }} -{{ end }} -{{ if not $featured }} - {{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} -{{ end }} -{{ if .Params.hideFeatureImage }}{{ $featured = false }}{{ end }} -{{ with $featured }} - {{ $featuredURL = .RelPermalink }} - {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} - {{ $featuredURL = (.Resize "600x").RelPermalink }} +{{ if not .Params.hideFeatureImage }} + {{ $images := $.Resources.ByType "image" }} + {{ range slice "*feature*" "*cover*" "*thumbnail*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} + {{ end }} + {{ if and .Params.featureimage (not $featured) }} + {{ $url:= .Params.featureimage }} + {{ $featured = resources.GetRemote $url }} + {{ end }} + {{ if not $featured }} + {{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} + {{ end }} + {{ with $featured }} + {{ $featuredURL = .RelPermalink }} + {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} + {{ $featuredURL = (.Resize "600x").RelPermalink }} + {{ end }} {{ end }} {{ end }} diff --git a/layouts/partials/article-link/simple.html b/layouts/partials/article-link/simple.html index 76aa3ce4..a3928414 100644 --- a/layouts/partials/article-link/simple.html +++ b/layouts/partials/article-link/simple.html @@ -32,24 +32,25 @@ {{ $articleClasses = delimit (slice $articleClasses "max-w-prose") " " }} {{ end }} -{{ $images := $.Resources.ByType "image" }} {{ $featured := "" }} {{ $featuredURL := "" }} -{{ range slice "*feature*" "*cover*" "*thumbnail*" }} - {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} -{{ end }} -{{ if and .Params.featureimage (not $featured) }} - {{ $url:= .Params.featureimage }} - {{ $featured = resources.GetRemote $url }} -{{ end }} -{{ if not $featured }} - {{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} -{{ end }} -{{ if .Params.hideFeatureImage }}{{ $featured = false }}{{ end }} -{{ with $featured }} - {{ $featuredURL = .RelPermalink }} - {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} - {{ $featuredURL = (.Resize "600x").RelPermalink }} +{{ if not .Params.hideFeatureImage }} + {{ $images := $.Resources.ByType "image" }} + {{ range slice "*feature*" "*cover*" "*thumbnail*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} + {{ end }} + {{ if and .Params.featureimage (not $featured) }} + {{ $url:= .Params.featureimage }} + {{ $featured = resources.GetRemote $url }} + {{ end }} + {{ if not $featured }} + {{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} + {{ end }} + {{ with $featured }} + {{ $featuredURL = .RelPermalink }} + {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} + {{ $featuredURL = (.Resize "600x").RelPermalink }} + {{ end }} {{ end }} {{ end }}