From 3f0dc1d6e1b7f917fc93ddc221da0104c70824e4 Mon Sep 17 00:00:00 2001
From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com>
Date: Sun, 7 Sep 2025 05:57:33 +0800
Subject: [PATCH] feat(hero): replace div with img tag
Changed: basic and thumbAndBackground layout
---
layouts/partials/hero/basic.html | 33 +++++----
layouts/partials/hero/thumbAndBackground.html | 72 +++++++++++--------
2 files changed, 60 insertions(+), 45 deletions(-)
diff --git a/layouts/partials/hero/basic.html b/layouts/partials/hero/basic.html
index 34ec0f3b..36c6f8dc 100644
--- a/layouts/partials/hero/basic.html
+++ b/layouts/partials/hero/basic.html
@@ -1,6 +1,7 @@
{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }}
{{ $featured := "" }}
+{{ $featuredURL := "" }}
{{ if .Params.featureimage }}
{{ $url := .Params.featureimage }}
{{ if or (strings.HasPrefix $url "http:") (strings.HasPrefix $url "https:") }}
@@ -27,18 +28,22 @@
{{ end }}
{{ end }}
-{{- with $featured -}}
- {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }}
- {{ with . }}
-
- {{ end }}
- {{ else }}
- {{ with .Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }}
-
- {{ end }}
+{{ with $featured }}
+ {{ $featuredURL = .RelPermalink }}
+ {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
+ {{ $size := (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }}
+ {{ $featuredURL = (.Resize $size).RelPermalink }}
{{ end }}
-{{- end -}}
+{{ end }}
+
+{{ with $featuredURL }}
+
+

+
+{{ end }}
diff --git a/layouts/partials/hero/thumbAndBackground.html b/layouts/partials/hero/thumbAndBackground.html
index a0b4cc94..e378537d 100644
--- a/layouts/partials/hero/thumbAndBackground.html
+++ b/layouts/partials/hero/thumbAndBackground.html
@@ -2,6 +2,7 @@
{{ $images := .Resources.ByType "image" }}
{{ $background := $images.GetMatch "*background*" }}
+{{ $backgroundURL := "" }}
{{ if not $background }}
{{ with .Site.Params.defaultBackgroundImage }}
@@ -17,7 +18,16 @@
{{ if not $background }}{{ $background = $images.GetMatch . }}{{ end }}
{{ end }}
+{{ with $background }}
+ {{ $backgroundURL = .RelPermalink }}
+ {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
+ {{ $size := (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }}
+ {{ $backgroundURL = (.Resize $size).RelPermalink }}
+ {{ end }}
+{{ end }}
+
{{ $featured := "" }}
+{{ $featuredURL := "" }}
{{ if .Params.featureimage }}
{{ $url := .Params.featureimage }}
{{ if or (strings.HasPrefix $url "http:") (strings.HasPrefix $url "https:") }}
@@ -44,6 +54,14 @@
{{ end }}
{{ end }}
+{{ with $featured }}
+ {{ $featuredURL = .RelPermalink }}
+ {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
+ {{ $size := (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }}
+ {{ $featuredURL = (.Resize $size).RelPermalink }}
+ {{ end }}
+{{ end }}
+
{{ $isParentList := eq (.Scratch.Get "scope") "list" }}
{{ $shouldBlur := $.Params.layoutBackgroundBlur | default (or
(and ($.Site.Params.article.layoutBackgroundBlur | default true) (not $isParentList))
@@ -51,40 +69,32 @@
)
}}
-{{- with $featured -}}
- {{ if or $disableImageOptimization (strings.HasSuffix . ".svg") }}
- {{ with . }}
-
- {{ end }}
- {{ else }}
- {{ with .Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }}
-
- {{ end }}
- {{ end }}
-{{- end -}}
-
-{{- with $background -}}
-
-
- {{ $imageURL := .RelPermalink }}
- {{ if not (or $disableImageOptimization (eq .MediaType.SubType "svg")) }}
- {{ $imageURL = (.Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x")).RelPermalink }}
- {{ end }}
+{{ with $featuredURL }}
+

+
+{{ end }}
+
+
+
+ {{ with $backgroundURL }}
+

-
-
-
-{{- end -}}
+ {{ end }}
+
+
+
{{ if $shouldBlur | default false }}