From e3194eca1ef12133fbdcf5157a495097f5087bd9 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sun, 31 Aug 2025 16:39:44 +0800 Subject: [PATCH 01/11] chore(article-link): remove unused .Params.images The `.Params.images` and `.Site.Params.images` have existed since the creation of the files but have never been referenced in the documentation since their initial commit (3cc1569fc1269baac374e9de20499aafc34a66fb) Also, Meta tags are not valid inside card elements --- assets/css/compiled/main.css | 5 -- layouts/partials/article-link/_shortcode.html | 52 +++++++--------- .../partials/article-link/card-related.html | 59 ++++++++----------- layouts/partials/article-link/card.html | 53 +++++++---------- layouts/partials/article-link/simple.html | 53 +++++++---------- 5 files changed, 90 insertions(+), 132 deletions(-) diff --git a/assets/css/compiled/main.css b/assets/css/compiled/main.css index 0eee6a96..ef5ca96d 100644 --- a/assets/css/compiled/main.css +++ b/assets/css/compiled/main.css @@ -3239,11 +3239,6 @@ body.zen-mode-enable { display: inline; } } - .ltr\:text-right { - &:where(:dir(ltr), [dir="ltr"], [dir="ltr"] *) { - text-align: right; - } - } .rtl\:left-0 { &:where(:dir(rtl), [dir="rtl"], [dir="rtl"] *) { left: calc(var(--spacing) * 0); diff --git a/layouts/partials/article-link/_shortcode.html b/layouts/partials/article-link/_shortcode.html index 2d11ca81..d22e07d6 100644 --- a/layouts/partials/article-link/_shortcode.html +++ b/layouts/partials/article-link/_shortcode.html @@ -36,38 +36,28 @@ class="absolute inset-0" aria-label="{{ $.Title }}"> - {{- with $target.Params.images -}} - {{- range first 6 . }} - - {{ end -}} - {{- else -}} - {{- $images := $target.Resources.ByType "image" -}} - {{- $featured := $images.GetMatch "*feature*" -}} - {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 -}} - {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} - {{ with . }} -
- {{ end }} - {{ else }} - {{ with .Resize "600x" }} -
- {{ end }} + {{ $images := $target.Resources.ByType "image" }} + {{ $featured := $images.GetMatch "*feature*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 }} + {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} + {{ with . }} +
{{ end }} - {{- else -}} - {{- with site.Params.images }} - - {{ end -}} - {{- end -}} - {{- end -}} + {{ else }} + {{ with .Resize "600x" }} +
+ {{ end }} + {{ end }} + {{ end }}
diff --git a/layouts/partials/article-link/card-related.html b/layouts/partials/article-link/card-related.html index 1bb08b23..5c04e221 100644 --- a/layouts/partials/article-link/card-related.html +++ b/layouts/partials/article-link/card-related.html @@ -5,41 +5,32 @@ {{ partial "article-link/_external-link.html" . | safeHTMLAttr }} class="absolute inset-0" aria-label="{{ $.Title }}"> - {{- with $.Params.images -}} - {{- range first 6 . }} - - {{ end -}} - {{- else -}} - {{- $images := $.Resources.ByType "image" -}} - {{- $featured := $images.GetMatch "*feature*" -}} - {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 -}} - {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} - {{ with . }} - - {{ end }} - {{ else }} - {{ with .Resize "600x" }} - - {{ end }} + + {{ $images := $.Resources.ByType "image" }} + {{ $featured := $images.GetMatch "*feature*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 }} + {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} + {{ with . }} + {{ end }} - {{- else -}} - {{- with $.Site.Params.images }} - - {{ end -}} - {{- end -}} - {{- end -}} + {{ else }} + {{ with .Resize "600x" }} + + {{ end }} + {{ end }} + {{ end }} {{ if and .Draft .Site.Params.article.showDraftLabel }} {{ partial "badge.html" (i18n "article.draft" | emojify) }} diff --git a/layouts/partials/article-link/card.html b/layouts/partials/article-link/card.html index 1112516f..cbce15df 100644 --- a/layouts/partials/article-link/card.html +++ b/layouts/partials/article-link/card.html @@ -5,38 +5,29 @@ {{ partial "article-link/_external-link.html" . | safeHTMLAttr }} class="absolute inset-0" aria-label="{{ $.Title }}"> - {{- with $.Params.images -}} - {{- range first 6 . }} - - {{ end -}} - {{- else -}} - {{- $images := $.Resources.ByType "image" -}} - {{- $featured := $images.GetMatch "*feature*" -}} - {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 -}} - {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} - {{ with . }} -
- {{ end }} - {{ else }} - {{ with .Resize "600x" }} -
- {{ end }} + + {{ $images := $.Resources.ByType "image" }} + {{ $featured := $images.GetMatch "*feature*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 }} + {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} + {{ with . }} +
{{ end }} - {{- else -}} - {{- with $.Site.Params.images }} - - {{ end -}} - {{- end -}} - {{- end -}} + {{ else }} + {{ with .Resize "600x" }} +
+ {{ end }} + {{ end }} + {{ end }} {{ if and .Draft .Site.Params.article.showDraftLabel }} {{ partial "badge.html" (i18n "article.draft" | emojify) }} diff --git a/layouts/partials/article-link/simple.html b/layouts/partials/article-link/simple.html index 07914ddc..c7e10e4f 100644 --- a/layouts/partials/article-link/simple.html +++ b/layouts/partials/article-link/simple.html @@ -33,38 +33,29 @@ {{ partial "article-link/_external-link.html" . | safeHTMLAttr }} class="absolute inset-0" aria-label="{{ $.Title }}"> - {{- with $.Params.images -}} - {{- range first 6 . }} - - {{ end -}} - {{- else -}} - {{- $images := $.Resources.ByType "image" -}} - {{- $featured := $images.GetMatch "*feature*" -}} - {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 -}} - {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} - {{ with . }} -
- {{ end }} - {{ else }} - {{ with .Resize "600x" }} -
- {{ end }} + + {{ $images := $.Resources.ByType "image" }} + {{ $featured := $images.GetMatch "*feature*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 }} + {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} + {{ with . }} +
{{ end }} - {{- else -}} - {{- with $.Site.Params.images }} - - {{ end -}} - {{- end -}} - {{- end -}} + {{ else }} + {{ with .Resize "600x" }} +
+ {{ end }} + {{ end }} + {{ end }}
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 02/11] 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 }} From 0f7f27b916ba72922612d452afd13a569982e54c Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sun, 31 Aug 2025 17:16:10 +0800 Subject: [PATCH 03/11] refactor(article-link): separate Go templates from HTML rendering Add descriptions for the purpose of each template. It takes time to figure out their use every time. --- layouts/partials/article-link/_shortcode.html | 42 +++++++++-------- .../partials/article-link/card-related.html | 42 ++++++++++------- layouts/partials/article-link/card.html | 46 +++++++++++-------- layouts/partials/article-link/simple.html | 44 ++++++++++-------- 4 files changed, 103 insertions(+), 71 deletions(-) diff --git a/layouts/partials/article-link/_shortcode.html b/layouts/partials/article-link/_shortcode.html index 3d13844b..62a7336e 100644 --- a/layouts/partials/article-link/_shortcode.html +++ b/layouts/partials/article-link/_shortcode.html @@ -1,3 +1,6 @@ +{{/* Used by + 1. article shortcode +*/}} {{ $target := .target }} {{ $shortcodeShowSummary := .showSummary }} {{ $shortcodeCompactSummary := .compactSummary }} @@ -29,30 +32,33 @@ {{ $articleClasses = delimit (slice $articleClasses "max-w-prose") " " }} {{ end }} +{{ $images := $target.Resources.ByType "image" }} +{{ $featured := $images.GetMatch "*feature*" }} +{{ $featuredURL := "" }} +{{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 }} + {{ end }} +{{ end }} +
- - {{ $images := $target.Resources.ByType "image" }} - {{ $featured := $images.GetMatch "*feature*" }} - {{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 }} - {{ end }} -
+ {{ with $featuredURL }} +
{{ end }}
diff --git a/layouts/partials/article-link/card-related.html b/layouts/partials/article-link/card-related.html index 9e5254b4..b5f65382 100644 --- a/layouts/partials/article-link/card-related.html +++ b/layouts/partials/article-link/card-related.html @@ -1,27 +1,35 @@ +{{/* Used by + 1. layouts/partials/related.html (related articles in single page) +*/}} {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} + +{{ $images := $.Resources.ByType "image" }} +{{ $featured := $images.GetMatch "*feature*" }} +{{ $featuredURL := "" }} +{{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 }} + +
- - {{ $images := $.Resources.ByType "image" }} - {{ $featured := $images.GetMatch "*feature*" }} - {{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 }} - + {{ with $featuredURL }} + {{ 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 df347f35..6d0bc58d 100644 --- a/layouts/partials/article-link/card.html +++ b/layouts/partials/article-link/card.html @@ -1,28 +1,38 @@ +{{/* Used by + 1. list.html and term.html (when the cardView option is enabled) + 2. Recent articles template (when the cardView option is enabled) + 3. Shortcode list.html +*/}} {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} + +{{ $images := $.Resources.ByType "image" }} +{{ $featured := $images.GetMatch "*feature*" }} +{{ $featuredURL := "" }} +{{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 }} + {{ end }} +{{ end }} + +
- - {{ $images := $.Resources.ByType "image" }} - {{ $featured := $images.GetMatch "*feature*" }} - {{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 }} - {{ end }} -
+ {{ with $featuredURL }} +
{{ 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 7d819dc0..e098fa4b 100644 --- a/layouts/partials/article-link/simple.html +++ b/layouts/partials/article-link/simple.html @@ -1,3 +1,8 @@ +{{/* Used by + 1. list.html and term.html (when the cardView option is not enabled) + 2. Recent articles template (when the cardView option is not enabled) + 3. Shortcode list.html +*/}} {{ $constrainItemsWidth := .Page.Site.Params.list.constrainItemsWidth | default false }} {{ $articleClasses := "group-hover-card group flex flex-wrap md:flex-nowrap article relative" }} @@ -27,30 +32,33 @@ {{ $articleClasses = delimit (slice $articleClasses "max-w-prose") " " }} {{ end }} +{{ $images := $.Resources.ByType "image" }} +{{ $featured := $images.GetMatch "*feature*" }} +{{ $featuredURL := "" }} +{{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 }} + {{ end }} +{{ end }} +
- - {{ $images := $.Resources.ByType "image" }} - {{ $featured := $images.GetMatch "*feature*" }} - {{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ 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 }} - {{ end }} -
+ {{ with $featuredURL }} +
{{ end }}
From ff3a6b42536fe5cdb45dc70a19d7deed3f9831e0 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sun, 31 Aug 2025 17:18:46 +0800 Subject: [PATCH 04/11] fix(article-link): explicitly set featured priority --- layouts/partials/article-link/_shortcode.html | 6 ++++-- 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, 16 insertions(+), 8 deletions(-) diff --git a/layouts/partials/article-link/_shortcode.html b/layouts/partials/article-link/_shortcode.html index 62a7336e..8c49b4a2 100644 --- a/layouts/partials/article-link/_shortcode.html +++ b/layouts/partials/article-link/_shortcode.html @@ -33,9 +33,11 @@ {{ end }} {{ $images := $target.Resources.ByType "image" }} -{{ $featured := $images.GetMatch "*feature*" }} +{{ $featured := "" }} {{ $featuredURL := "" }} -{{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end }} +{{ 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 }} diff --git a/layouts/partials/article-link/card-related.html b/layouts/partials/article-link/card-related.html index b5f65382..52534210 100644 --- a/layouts/partials/article-link/card-related.html +++ b/layouts/partials/article-link/card-related.html @@ -4,9 +4,11 @@ {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} {{ $images := $.Resources.ByType "image" }} -{{ $featured := $images.GetMatch "*feature*" }} +{{ $featured := "" }} {{ $featuredURL := "" }} -{{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end }} +{{ 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 }} diff --git a/layouts/partials/article-link/card.html b/layouts/partials/article-link/card.html index 6d0bc58d..29e923c1 100644 --- a/layouts/partials/article-link/card.html +++ b/layouts/partials/article-link/card.html @@ -6,9 +6,11 @@ {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} {{ $images := $.Resources.ByType "image" }} -{{ $featured := $images.GetMatch "*feature*" }} +{{ $featured := "" }} {{ $featuredURL := "" }} -{{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end }} +{{ 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 }} diff --git a/layouts/partials/article-link/simple.html b/layouts/partials/article-link/simple.html index e098fa4b..76aa3ce4 100644 --- a/layouts/partials/article-link/simple.html +++ b/layouts/partials/article-link/simple.html @@ -33,9 +33,11 @@ {{ end }} {{ $images := $.Resources.ByType "image" }} -{{ $featured := $images.GetMatch "*feature*" }} +{{ $featured := "" }} {{ $featuredURL := "" }} -{{ if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end }} +{{ 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 }} 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 05/11] 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 }} 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 06/11] 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")) }} From cb479d56931738ebfa969dbbc15578741c0ff055 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sun, 31 Aug 2025 17:58:04 +0800 Subject: [PATCH 07/11] feat(hero): 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/hero/background.html | 27 +++++++----- layouts/partials/hero/basic.html | 27 +++++++----- layouts/partials/hero/big.html | 25 +++++++---- layouts/partials/hero/thumbAndBackground.html | 41 ++++++++++++------- 4 files changed, 76 insertions(+), 44 deletions(-) diff --git a/layouts/partials/hero/background.html b/layouts/partials/hero/background.html index caa0dd96..026faad6 100644 --- a/layouts/partials/hero/background.html +++ b/layouts/partials/hero/background.html @@ -1,16 +1,23 @@ {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} -{{- $images := .Resources.ByType "image" -}} -{{- $featured := $images.GetMatch "*background*" -}} -{{- if not $featured }}{{ $featured = $images.GetMatch "*feature*" }}{{ end -}} -{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} - -{{ if and .Params.featureimage (not $featured) }} - {{- $url:= .Params.featureimage -}} - {{ $featured = resources.GetRemote $url }} +{{ $featured := "" }} +{{ if .Params.featureimage }} + {{ $url := .Params.featureimage }} + {{ if or (strings.HasPrefix $url "http:") (strings.HasPrefix $url "https:") }} + {{ $featured = resources.GetRemote $url }} + {{ else }} + {{ $featured = resources.Get $url }} + {{ end }} {{ end }} -{{- if not $featured }} +{{ if not $featured }} + {{ $images := $.Resources.ByType "image" }} + {{ range slice "*background*" "*feature*" "*cover*" "*thumbnail*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} + {{ end }} +{{ end }} + +{{ if not $featured }} {{ with .Site.Params.defaultBackgroundImage }} {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} {{ $featured = resources.GetRemote . }} @@ -18,7 +25,7 @@ {{ $featured = resources.Get . }} {{ end }} {{ end }} -{{ end -}} +{{ end }} {{ $isParentList := eq (.Scratch.Get "scope") "list" }} {{ $shouldBlur := $.Params.layoutBackgroundBlur | default (or diff --git a/layouts/partials/hero/basic.html b/layouts/partials/hero/basic.html index 54e84ed3..34ec0f3b 100644 --- a/layouts/partials/hero/basic.html +++ b/layouts/partials/hero/basic.html @@ -1,16 +1,23 @@ {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} -{{- $images := .Resources.ByType "image" -}} -{{- $featured := $images.GetMatch "*background*" -}} -{{- if not $featured }}{{ $featured = $images.GetMatch "*feature*" }}{{ end -}} -{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} - -{{ if and .Params.featureimage (not $featured) }} - {{- $url:= .Params.featureimage -}} - {{ $featured = resources.GetRemote $url }} +{{ $featured := "" }} +{{ if .Params.featureimage }} + {{ $url := .Params.featureimage }} + {{ if or (strings.HasPrefix $url "http:") (strings.HasPrefix $url "https:") }} + {{ $featured = resources.GetRemote $url }} + {{ else }} + {{ $featured = resources.Get $url }} + {{ end }} {{ end }} -{{- if not $featured }} +{{ if not $featured }} + {{ $images := $.Resources.ByType "image" }} + {{ range slice "*background*" "*feature*" "*cover*" "*thumbnail*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} + {{ end }} +{{ end }} + +{{ if not $featured }} {{ with .Site.Params.defaultBackgroundImage }} {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} {{ $featured = resources.GetRemote . }} @@ -18,7 +25,7 @@ {{ $featured = resources.Get . }} {{ end }} {{ end }} -{{ end -}} +{{ end }} {{- with $featured -}} {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} diff --git a/layouts/partials/hero/big.html b/layouts/partials/hero/big.html index 7fbaeba6..2a0ad286 100644 --- a/layouts/partials/hero/big.html +++ b/layouts/partials/hero/big.html @@ -1,16 +1,23 @@ {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} -{{- $images := .Resources.ByType "image" -}} -{{- $featured := $images.GetMatch "*background*" -}} -{{- if not $featured }}{{ $featured = $images.GetMatch "*feature*" }}{{ end -}} -{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} - +{{ $featured := "" }} {{ if .Params.featureimage }} - {{- $url:= .Params.featureimage -}} - {{- if not $featured }}{{ $featured = resources.GetRemote $url }}{{ end -}} + {{ $url := .Params.featureimage }} + {{ if or (strings.HasPrefix $url "http:") (strings.HasPrefix $url "https:") }} + {{ $featured = resources.GetRemote $url }} + {{ else }} + {{ $featured = resources.Get $url }} + {{ end }} {{ end }} -{{- if not $featured }} +{{ if not $featured }} + {{ $images := $.Resources.ByType "image" }} + {{ range slice "*background*" "*feature*" "*cover*" "*thumbnail*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} + {{ end }} +{{ end }} + +{{ if not $featured }} {{ with .Site.Params.defaultBackgroundImage }} {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} {{ $featured = resources.GetRemote . }} @@ -18,7 +25,7 @@ {{ $featured = resources.Get . }} {{ end }} {{ end }} -{{ end -}} +{{ end }} {{ $caption := "" }} {{ if .Params.featureimagecaption }} diff --git a/layouts/partials/hero/thumbAndBackground.html b/layouts/partials/hero/thumbAndBackground.html index 9be2cef0..a0b4cc94 100644 --- a/layouts/partials/hero/thumbAndBackground.html +++ b/layouts/partials/hero/thumbAndBackground.html @@ -1,9 +1,9 @@ {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} -{{- $images := .Resources.ByType "image" -}} -{{- $background := $images.GetMatch "*background*" -}} +{{ $images := .Resources.ByType "image" }} +{{ $background := $images.GetMatch "*background*" }} -{{- if not $background }} +{{ if not $background }} {{ with .Site.Params.defaultBackgroundImage }} {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} {{ $background = resources.GetRemote . }} @@ -11,19 +11,30 @@ {{ $background = resources.Get . }} {{ end }} {{ end }} -{{ end -}} - -{{- if not $background }}{{ $background = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} -{{- if not $background }}{{ $background = $images.GetMatch "*feature*" }}{{ end -}} -{{- $featured := $images.GetMatch "*feature*" -}} -{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} -{{ if .Params.featureimage }} - {{- $url:= .Params.featureimage -}} - {{- if not $featured }}{{ $featured = resources.GetRemote $url }}{{ end -}} {{ end }} -{{- if not $featured }}{{ $featured = $images.GetMatch "*background*" }}{{ end -}} -{{- if not $featured }} +{{ range slice "*cover*" "*thumbnail*" "*feature*" }} + {{ if not $background }}{{ $background = $images.GetMatch . }}{{ end }} +{{ end }} + +{{ $featured := "" }} +{{ if .Params.featureimage }} + {{ $url := .Params.featureimage }} + {{ if or (strings.HasPrefix $url "http:") (strings.HasPrefix $url "https:") }} + {{ $featured = resources.GetRemote $url }} + {{ else }} + {{ $featured = resources.Get $url }} + {{ end }} +{{ end }} + +{{ if not $featured }} + {{ $images := $.Resources.ByType "image" }} + {{ range slice "*feature*" "*cover*" "*thumbnail*" "*background*" }} + {{ if not $featured }}{{ $featured = $images.GetMatch . }}{{ end }} + {{ end }} +{{ end }} + +{{ if not $featured }} {{ with .Site.Params.defaultFeaturedImage }} {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} {{ $featured = resources.GetRemote . }} @@ -31,7 +42,7 @@ {{ $featured = resources.Get . }} {{ end }} {{ end }} -{{ end -}} +{{ end }} {{ $isParentList := eq (.Scratch.Get "scope") "list" }} {{ $shouldBlur := $.Params.layoutBackgroundBlur | default (or From 8911ac843ad147c35a18ea1b0447dfd6493c7ff3 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sun, 31 Aug 2025 22:43:51 +0800 Subject: [PATCH 08/11] chore(term-link): remove unused .Params.images --- layouts/partials/term-link/card.html | 36 ++++++++++------------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/layouts/partials/term-link/card.html b/layouts/partials/term-link/card.html index 280a74d4..4fa7ca31 100644 --- a/layouts/partials/term-link/card.html +++ b/layouts/partials/term-link/card.html @@ -1,31 +1,21 @@
+ class="border-neutral-200 dark:border-neutral-700 border-2 rounded overflow-hidden shadow-2xl relative"> {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} - {{- with site.Params.images -}} - {{- range first 6 . }} - - {{ end -}} - {{- else -}} - {{- $images := .Page.Resources.ByType "image" -}} - {{- $featured := $images.GetMatch "*feature*" -}} - {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} - {{- with $featured -}} - {{ if $disableImageOptimization }} - {{ with . }} -
- {{ end }} - {{ else }} - {{ with .Resize "600x" }} -
- {{ end }} + {{- $images := .Page.Resources.ByType "image" -}} + {{- $featured := $images.GetMatch "*feature*" -}} + {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} + {{- with $featured -}} + {{ if $disableImageOptimization }} + {{ with . }} +
{{ end }} - {{- else -}} - {{- with site.Params.images }} - - {{ end -}} - {{- end -}} + {{ else }} + {{ with .Resize "600x" }} +
+ {{ end }} + {{ end }} {{- end -}} {{ if site.Params.taxonomy.showTermCount | default true }} From b1b7aa1f42c2f49f0469215ee1909c7aca70080f Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sat, 6 Sep 2025 14:50:24 +0800 Subject: [PATCH 09/11] feat(article-link): reimplement card hover using ::before method The previous method was not intuitive since there was nothing in the
tag, and required group-xxx classes for every element. The new pseudo element method fixes those problems, see: https://kittygiraudel.com/2022/04/02/accessible-cards/ --- assets/css/compiled/main.css | 22 +++++----- assets/css/main.css | 5 --- layouts/partials/article-link/_shortcode.html | 43 +++++++++---------- .../partials/article-link/card-related.html | 40 ++++++++--------- layouts/partials/article-link/card.html | 40 ++++++++--------- layouts/partials/article-link/simple.html | 40 ++++++++--------- 6 files changed, 89 insertions(+), 101 deletions(-) diff --git a/assets/css/compiled/main.css b/assets/css/compiled/main.css index ef5ca96d..ce5cc6a3 100644 --- a/assets/css/compiled/main.css +++ b/assets/css/compiled/main.css @@ -2543,13 +2543,6 @@ body.zen-mode-enable { } } } - .group-hover\:underline-offset-2 { - &:is(:where(.group):hover *) { - @media (hover: hover) { - text-underline-offset: 2px; - } - } - } .group-hover\:opacity-100 { &:is(:where(.group):hover *) { @media (hover: hover) { @@ -2640,6 +2633,18 @@ body.zen-mode-enable { border-top-color: transparent; } } + .before\:absolute { + &::before { + content: var(--tw-content); + position: absolute; + } + } + .before\:inset-0 { + &::before { + content: var(--tw-content); + inset: calc(var(--spacing) * 0); + } + } .after\:clear-both { &::after { content: var(--tw-content); @@ -3850,9 +3855,6 @@ pre { text-decoration-thickness: 3px; text-underline-offset: 4px; } -.group-hover-card:hover:has(.group-hover-cancel:hover) .group-hover-card-title { - text-decoration: none !important; -} @layer base { [type='text'],input:where(:not([type])),[type='email'],[type='url'],[type='password'],[type='number'],[type='date'],[type='datetime-local'],[type='month'],[type='search'],[type='tel'],[type='time'],[type='week'],[multiple],textarea,select { appearance: none; diff --git a/assets/css/main.css b/assets/css/main.css index 023eef06..db602162 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -278,8 +278,3 @@ pre { text-decoration-thickness: 3px; text-underline-offset: 4px; } - -/* Cancel group hover if .group-hover-card contains .group-hover-cancel*/ -.group-hover-card:hover:has(.group-hover-cancel:hover) .group-hover-card-title { - text-decoration: none !important; -} diff --git a/layouts/partials/article-link/_shortcode.html b/layouts/partials/article-link/_shortcode.html index c90f903d..8da60d8f 100644 --- a/layouts/partials/article-link/_shortcode.html +++ b/layouts/partials/article-link/_shortcode.html @@ -7,7 +7,7 @@ {{ $constrainItemsWidth := site.Params.list.constrainItemsWidth | default false }} {{ $disableImageOptimization := site.Params.disableImageOptimization | default false }} -{{ $articleClasses := "group-hover-card group flex flex-wrap md:flex-nowrap article relative" }} +{{ $articleClasses := "flex flex-wrap md:flex-nowrap article relative" }} {{ if site.Params.list.showCards }} {{ $articleClasses = delimit (slice $articleClasses "border border-neutral-200 dark:border-neutral-700 border-2 rounded-md overflow-hidden") " " }} {{ else }} @@ -63,33 +63,30 @@
- {{ with $featuredURL }}
{{ end }}
- {{ with $target.Params.externalUrl }} -
- - {{ else }} -
- {{ $target.Title | emojify }} -
- {{ end }} + {{ else }} +
+ {{ $target.Title | emojify }} +
+ {{ end }} +
{{ if and $target.Draft site.Params.article.showDraftLabel }}
{{ partial "badge.html" (i18n "article.draft" | emojify) }} @@ -99,7 +96,7 @@ {{ partial "extend-article-link.html" $target }} {{ end }}
-
+
{{ partial "article-meta/basic.html" $target }}
{{ $showSummary := false }} diff --git a/layouts/partials/article-link/card-related.html b/layouts/partials/article-link/card-related.html index 6ce15e3c..2ee56640 100644 --- a/layouts/partials/article-link/card-related.html +++ b/layouts/partials/article-link/card-related.html @@ -32,11 +32,7 @@
- + class="relative min-h-full min-w-full overflow-hidden rounded border border-2 border-neutral-200 shadow-2xl dark:border-neutral-700"> {{ with $featuredURL }} {{ end }} @@ -46,22 +42,24 @@ {{ end }}
- {{ with .Params.externalUrl }} -
- {{ $.Title | emojify }} - - - - -
- {{ else }} -
- {{ .Title | emojify }} -
- {{ end }} -
+ + {{ with .Params.externalUrl }} +
+ {{ $.Title | emojify }} + + + + +
+ {{ else }} +
+ {{ .Title | emojify }} +
+ {{ end }} +
+
{{ partial "article-meta/basic.html" . }}
{{ if .Params.showSummary | default (.Site.Params.list.showSummary | default false) }} diff --git a/layouts/partials/article-link/card.html b/layouts/partials/article-link/card.html index 86066cd5..00692131 100644 --- a/layouts/partials/article-link/card.html +++ b/layouts/partials/article-link/card.html @@ -36,11 +36,7 @@
- + class="relative min-h-full min-w-full overflow-hidden rounded border border-2 border-neutral-200 shadow-2xl dark:border-neutral-700"> {{ with $featuredURL }}
{{ end }} @@ -50,22 +46,24 @@ {{ end }}
- {{ with .Params.externalUrl }} -
- {{ $.Title | emojify }} - - - - -
- {{ else }} -
- {{ .Title | emojify }} -
- {{ end }} -
+ + {{ with .Params.externalUrl }} +
+ {{ $.Title | emojify }} + + + + +
+ {{ else }} +
+ {{ .Title | emojify }} +
+ {{ end }} +
+
{{ partial "article-meta/basic.html" . }}
{{ if .Params.showSummary | default (.Site.Params.list.showSummary | default false) }} diff --git a/layouts/partials/article-link/simple.html b/layouts/partials/article-link/simple.html index 5fca0df8..cf7a342f 100644 --- a/layouts/partials/article-link/simple.html +++ b/layouts/partials/article-link/simple.html @@ -5,7 +5,7 @@ */}} {{ $constrainItemsWidth := .Page.Site.Params.list.constrainItemsWidth | default false }} -{{ $articleClasses := "group-hover-card group flex flex-wrap md:flex-nowrap article relative" }} +{{ $articleClasses := "flex flex-wrap md:flex-nowrap article relative" }} {{ if .Site.Params.list.showCards }} {{ $articleClasses = delimit (slice $articleClasses "border border-neutral-200 dark:border-neutral-700 border-2 rounded-md overflow-hidden") " " }} {{ else }} @@ -63,30 +63,28 @@
- {{ with $featuredURL }}
{{ end }}
- {{ with .Params.externalUrl }} -
- {{ $.Title | emojify }} - - - - -
- {{ else }} -
- {{ .Title | emojify }} -
- {{ end }} + + {{ with .Params.externalUrl }} +
+ {{ $.Title | emojify }} + + + + +
+ {{ else }} +
+ {{ .Title | emojify }} +
+ {{ end }} +
{{ if and .Draft .Site.Params.article.showDraftLabel }}
{{ partial "badge.html" (i18n "article.draft" | emojify) }}
{{ end }} @@ -94,7 +92,7 @@ {{ partial "extend-article-link.html" . }} {{ end }}
-
+
{{ partial "article-meta/basic.html" . }}
{{ if .Params.showSummary | default (.Site.Params.list.showSummary | default false) }} From 5bab41062a7b30c724dd466e8abd38fcbf9a331c Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sat, 6 Sep 2025 14:55:40 +0800 Subject: [PATCH 10/11] refactor(article-link): remove unnecessary with syntax --- layouts/partials/article-link/_shortcode.html | 24 +++++++------------ .../partials/article-link/card-related.html | 14 ++++------- layouts/partials/article-link/card.html | 14 ++++------- layouts/partials/article-link/simple.html | 14 ++++------- 4 files changed, 24 insertions(+), 42 deletions(-) diff --git a/layouts/partials/article-link/_shortcode.html b/layouts/partials/article-link/_shortcode.html index 8da60d8f..36e9450e 100644 --- a/layouts/partials/article-link/_shortcode.html +++ b/layouts/partials/article-link/_shortcode.html @@ -71,21 +71,15 @@ - {{ with $target.Params.externalUrl }} -
-
- {{ $target.Title | emojify }} - - - - -
-
- {{ else }} -
- {{ $target.Title | emojify }} -
- {{ end }} +
+ {{ $target.Title | emojify }} + {{ if $target.Params.externalUrl }} + + + + + {{ end }} +
{{ if and $target.Draft site.Params.article.showDraftLabel }}
diff --git a/layouts/partials/article-link/card-related.html b/layouts/partials/article-link/card-related.html index 2ee56640..5510d4af 100644 --- a/layouts/partials/article-link/card-related.html +++ b/layouts/partials/article-link/card-related.html @@ -45,19 +45,15 @@ - {{ with .Params.externalUrl }} -
- {{ $.Title | emojify }} +
+ {{ .Title | emojify }} + {{ if .Params.externalUrl }} -
- {{ else }} -
- {{ .Title | emojify }} -
- {{ end }} + {{ end }} +
{{ partial "article-meta/basic.html" . }} diff --git a/layouts/partials/article-link/card.html b/layouts/partials/article-link/card.html index 00692131..c0927192 100644 --- a/layouts/partials/article-link/card.html +++ b/layouts/partials/article-link/card.html @@ -49,19 +49,15 @@ - {{ with .Params.externalUrl }} -
- {{ $.Title | emojify }} +
+ {{ .Title | emojify }} + {{ if .Params.externalUrl }} -
- {{ else }} -
- {{ .Title | emojify }} -
- {{ end }} + {{ end }} +
{{ partial "article-meta/basic.html" . }} diff --git a/layouts/partials/article-link/simple.html b/layouts/partials/article-link/simple.html index cf7a342f..ce087db9 100644 --- a/layouts/partials/article-link/simple.html +++ b/layouts/partials/article-link/simple.html @@ -71,19 +71,15 @@ - {{ with .Params.externalUrl }} -
- {{ $.Title | emojify }} +
+ {{ .Title | emojify }} + {{ if .Params.externalUrl }} -
- {{ else }} -
- {{ .Title | emojify }} -
- {{ end }} + {{ end }} +
{{ if and .Draft .Site.Params.article.showDraftLabel }}
{{ partial "badge.html" (i18n "article.draft" | emojify) }}
From 340364f31a96d1a2d0f94fc6199fd536d1a5effe Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sat, 6 Sep 2025 15:36:21 +0800 Subject: [PATCH 11/11] feat(article-link): use semantic HTML --- layouts/partials/article-link/_shortcode.html | 12 +++---- .../partials/article-link/card-related.html | 32 ++++++++++--------- layouts/partials/article-link/card.html | 32 ++++++++++--------- layouts/partials/article-link/simple.html | 12 +++---- 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/layouts/partials/article-link/_shortcode.html b/layouts/partials/article-link/_shortcode.html index 36e9450e..50381dcc 100644 --- a/layouts/partials/article-link/_shortcode.html +++ b/layouts/partials/article-link/_shortcode.html @@ -62,16 +62,16 @@ {{ end }} -
+
+ diff --git a/layouts/partials/article-link/card-related.html b/layouts/partials/article-link/card-related.html index 5510d4af..f333c223 100644 --- a/layouts/partials/article-link/card-related.html +++ b/layouts/partials/article-link/card-related.html @@ -31,7 +31,7 @@ {{ end }} -
{{ with $featuredURL }} @@ -42,19 +42,21 @@ {{ end }}
-
+ diff --git a/layouts/partials/article-link/card.html b/layouts/partials/article-link/card.html index c0927192..6f9e9ba9 100644 --- a/layouts/partials/article-link/card.html +++ b/layouts/partials/article-link/card.html @@ -35,7 +35,7 @@ {{ end }} -
{{ with $featuredURL }}
@@ -46,19 +46,21 @@ {{ end }}
-
+ diff --git a/layouts/partials/article-link/simple.html b/layouts/partials/article-link/simple.html index ce087db9..54b7c3b0 100644 --- a/layouts/partials/article-link/simple.html +++ b/layouts/partials/article-link/simple.html @@ -62,16 +62,16 @@ {{ end }} -
+
+