From 9c1d56e0e76140166ce639301cfcfb17f692f1c5 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sun, 31 Aug 2025 17:41:48 +0800 Subject: [PATCH] feat(article-link): support internal links for `featureimage` This commit also gives the `featureimage` frontmatter the highest priority, preventing it from being overridden by hidden logic. --- layouts/partials/article-link/_shortcode.html | 25 ++++++++++++------- .../partials/article-link/card-related.html | 23 +++++++++++------ layouts/partials/article-link/card.html | 23 +++++++++++------ layouts/partials/article-link/simple.html | 23 +++++++++++------ 4 files changed, 61 insertions(+), 33 deletions(-) diff --git a/layouts/partials/article-link/_shortcode.html b/layouts/partials/article-link/_shortcode.html index b154d594..c90f903d 100644 --- a/layouts/partials/article-link/_shortcode.html +++ b/layouts/partials/article-link/_shortcode.html @@ -34,18 +34,25 @@ {{ $featured := "" }} {{ $featuredURL := "" }} -{{ 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 }} +{{ if not $target.Params.hideFeatureImage }} + {{ with $target.Params.featureimage }} + {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} + {{ $featured = resources.GetRemote . }} + {{ else }} + {{ $featured = resources.Get . }} + {{ end }} {{ end }} + {{ if not $featured }} - {{ with site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} + {{ $images := $target.Resources.ByType "image" }} + {{ range slice "*feature*" "*cover*" "*thumbnail*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} + {{ end }} + {{ if not $featured }} + {{ with site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} + {{ end }} {{ end }} + {{ with $featured }} {{ $featuredURL = .RelPermalink }} {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} diff --git a/layouts/partials/article-link/card-related.html b/layouts/partials/article-link/card-related.html index 2a933a3b..6ce15e3c 100644 --- a/layouts/partials/article-link/card-related.html +++ b/layouts/partials/article-link/card-related.html @@ -5,17 +5,24 @@ {{ $featured := "" }} {{ $featuredURL := "" }} -{{ $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 }} +{{ with .Params.featureimage }} + {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} + {{ $featured = resources.GetRemote . }} + {{ else }} + {{ $featured = resources.Get . }} + {{ end }} {{ end }} + {{ if not $featured }} - {{ with site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} + {{ $images := $.Resources.ByType "image" }} + {{ range slice "*feature*" "*cover*" "*thumbnail*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} + {{ end }} + {{ if not $featured }} + {{ with site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} + {{ end }} {{ end }} + {{ with $featured }} {{ $featuredURL = .RelPermalink }} {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} diff --git a/layouts/partials/article-link/card.html b/layouts/partials/article-link/card.html index 5a9c4aa1..86066cd5 100644 --- a/layouts/partials/article-link/card.html +++ b/layouts/partials/article-link/card.html @@ -8,17 +8,24 @@ {{ $featured := "" }} {{ $featuredURL := "" }} {{ 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 }} + {{ with .Params.featureimage }} + {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} + {{ $featured = resources.GetRemote . }} + {{ else }} + {{ $featured = resources.Get . }} + {{ end }} {{ end }} + {{ if not $featured }} - {{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} + {{ $images := $.Resources.ByType "image" }} + {{ range slice "*feature*" "*cover*" "*thumbnail*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} + {{ end }} + {{ if not $featured }} + {{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} + {{ end }} {{ end }} + {{ with $featured }} {{ $featuredURL = .RelPermalink }} {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }} diff --git a/layouts/partials/article-link/simple.html b/layouts/partials/article-link/simple.html index a3928414..5fca0df8 100644 --- a/layouts/partials/article-link/simple.html +++ b/layouts/partials/article-link/simple.html @@ -35,17 +35,24 @@ {{ $featured := "" }} {{ $featuredURL := "" }} {{ 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 }} + {{ with .Params.featureimage }} + {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} + {{ $featured = resources.GetRemote . }} + {{ else }} + {{ $featured = resources.Get . }} + {{ end }} {{ end }} + {{ if not $featured }} - {{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} + {{ $images := $.Resources.ByType "image" }} + {{ range slice "*feature*" "*cover*" "*thumbnail*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} + {{ end }} + {{ if not $featured }} + {{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }} + {{ end }} {{ end }} + {{ with $featured }} {{ $featuredURL = .RelPermalink }} {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}