From 1736cafcf4fef8c732b23b8ad6eab348756f8c3d Mon Sep 17 00:00:00 2001 From: Served Smart <195884188+servedsmart@users.noreply.github.com> Date: Sun, 22 Jun 2025 00:26:30 +0200 Subject: [PATCH 1/3] :recycle: Refactor: Move inline styles containing background-image: out of line This greatly reduces the number of inline styles in the project and enhances maintainability by avoiding a lot of duplicate code. This also reduces the number of hashes required for a CSP since all previous background-image inline styles are now in main.css. --- .../partials/article-link/card-related.html | 43 +++--- layouts/partials/article-link/card.html | 46 +++--- layouts/partials/article-link/simple.html | 47 +++--- layouts/partials/head.html | 32 +++++ layouts/partials/hero/background.html | 91 ++++++------ layouts/partials/hero/basic.html | 52 +++---- layouts/partials/hero/thumbAndBackground.html | 135 ++++++++---------- layouts/partials/term-link/card.html | 37 +++-- 8 files changed, 239 insertions(+), 244 deletions(-) diff --git a/layouts/partials/article-link/card-related.html b/layouts/partials/article-link/card-related.html index f84bdd81..f576763a 100644 --- a/layouts/partials/article-link/card-related.html +++ b/layouts/partials/article-link/card-related.html @@ -1,4 +1,3 @@ -{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} {{ with .Params.externalUrl }} {{ else }} @@ -10,30 +9,30 @@ {{- 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 . }} - + {{ $images := $.Resources.ByType "image" }} + {{ $featuredImage := $images.GetMatch "*feature*" }} + {{ if not $featuredImage }} + {{ $featuredImage = $images.GetMatch "{*cover*,*thumbnail*}" }} {{ end }} - {{ else }} - {{ with .Resize "600x" }} - + {{ if and (not $featuredImage) .Params.featureimage }} + {{ $featuredImage = resources.GetRemote .Params.featureimage }} + {{ end }} + {{ if not $featuredImage }} + {{ $featuredImage = resources.Get .Site.Params.defaultFeaturedImage }} + {{ end }} + {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} + {{ if and ($featuredImage) (not (or ($disableImageOptimization) (strings.HasSuffix $featuredImage.Name ".svg"))) }} + {{ $featuredImage = $featuredImage.Resize "600x" }} + {{ end }} + {{ with $featuredImage }} + {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} + + {{ else }} + {{ with $.Site.Params.images }} + {{ end }} {{ end }} - {{- else -}} - {{- with $.Site.Params.images }} - {{ end -}} - {{- end -}} - {{- 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 c876e35d..0ce06e75 100644 --- a/layouts/partials/article-link/card.html +++ b/layouts/partials/article-link/card.html @@ -1,4 +1,3 @@ -{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} {{ with .Params.externalUrl }} {{ else }} @@ -10,30 +9,33 @@ {{- 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 . }} -
+ {{ $images := $.Resources.ByType "image" }} + {{ $featuredImage := $images.GetMatch "*feature*" }} + {{ if not $featuredImage }} + {{ $featuredImage = $images.GetMatch "{*cover*,*thumbnail*}" }} {{ end }} - {{ else }} - {{ with .Resize "600x" }} -
+ {{ if and (not $featuredImage) .Params.featureimage }} + {{ $featuredImage = resources.GetRemote .Params.featureimage }} + {{ end }} + {{ if not $featuredImage }} + {{ $featuredImage = resources.Get .Site.Params.defaultFeaturedImage }} + {{ end }} + {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} + {{ if and ($featuredImage) (not (or ($disableImageOptimization) (strings.HasSuffix $featuredImage.Name ".svg"))) }} + {{ $featuredImage = $featuredImage.Resize "600x" }} + {{ end }} + {{ if .Params.hideFeatureImage }} + {{ $featuredImage = false }} + {{ end }} + {{ with $featuredImage }} + {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} +
+ {{ else }} + {{ with $.Site.Params.images }} + {{ end }} {{ end }} - {{- else -}} - {{- with $.Site.Params.images }} - {{ end -}} - {{- end -}} - {{- 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 5299d663..e56a2afd 100644 --- a/layouts/partials/article-link/simple.html +++ b/layouts/partials/article-link/simple.html @@ -14,8 +14,6 @@ {{ $articleImageClasses = delimit (slice $articleImageClasses "thumbnailshadow md:mr-7") " " }} {{ end }} -{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} - {{ $articleInnerClasses := "" }} {{ if .Site.Params.list.showCards }} {{ $articleInnerClasses = delimit (slice $articleInnerClasses "p-4") " " }} @@ -37,30 +35,33 @@ {{- 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 }} + {{ $images := $.Resources.ByType "image" }} + {{ $featuredImage := $images.GetMatch "*feature*" }} + {{ if not $featuredImage }} + {{ $featuredImage = $images.GetMatch "{*cover*,*thumbnail*}" }} + {{ end }} + {{ if and (not $featuredImage) .Params.featureimage }} + {{ $featuredImage = resources.GetRemote .Params.featureimage }} + {{ end }} + {{ if not $featuredImage }} + {{ $featuredImage = resources.Get .Site.Params.defaultFeaturedImage }} + {{ end }} + {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} + {{ if and ($featuredImage) (not (or ($disableImageOptimization) (strings.HasSuffix $featuredImage.Name ".svg"))) }} + {{ $featuredImage = $featuredImage.Resize "600x" }} + {{ end }} + {{ if .Params.hideFeatureImage }} + {{ $featuredImage = false }} + {{ end }} + {{ with $featuredImage }} + {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} +
{{ else }} - {{ with .Resize "600x" }} -
+ {{ with $.Site.Params.images }} + {{ end }} {{ end }} - {{- else -}} - {{- with $.Site.Params.images }} - {{ end -}} - {{- end -}} - {{- end -}} + {{ end }}
diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 424f8c98..78509d3e 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -45,6 +45,38 @@ {{ if $cssCustom }} {{ $assets.Add "css" (slice $cssCustom) }} {{ end }} + + {{ $images := slice }} + {{ $backgroundAndfeaturedImages := slice }} + {{ range .Site.Pages }} + {{ $images = $images | append (.Page.Resources.ByType "image") }} + {{ if .Params.featureimage }} + {{ $backgroundAndfeaturedImages = $backgroundAndfeaturedImages | append (resources.GetRemote .Params.featureimage) }} + {{ end }} + {{ end }} + {{ $backgroundAndfeaturedImages = $backgroundAndfeaturedImages | append ($images.Match "{*background*,*feature*,*cover*,*thumbnail*}") }} + {{ $siteParams := slice .Site.Params.defaultFeaturedImage .Site.Params.defaultBackgroundImage }} + {{ range $siteParams }} + {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} + {{ $backgroundAndfeaturedImages = $backgroundAndfeaturedImages | append (resources.GetRemote .) }} + {{ else }} + {{ $backgroundAndfeaturedImages = $backgroundAndfeaturedImages | append (resources.Get .) }} + {{ end }} + {{ end }} + {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} + {{ range $backgroundAndfeaturedImages }} + {{ $backgroundAndfeaturedImages := . }} + {{ if not (or ($disableImageOptimization) (strings.HasSuffix .Name ".svg")) }} + {{ $backgroundAndfeaturedImages = .Resize "600x" }} + {{ end }} + {{ with $backgroundAndfeaturedImages }} + {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} + {{ $cssBackgroundImage := printf ".%s { background-image: url(\"%s\"); }" $className .RelPermalink }} + {{ $cssBackgroundImage = $cssBackgroundImage | resources.FromString "css/background-image.css" }} + {{ $assets.Add "css" (slice $cssBackgroundImage) }} + {{ end }} + {{ end }} + {{ $bundleCSS := $assets.Get "css" | resources.Concat "css/main.bundle.css" | resources.Minify | resources.Fingerprint (.Site.Params.fingerprintAlgorithm | default "sha512") }}
-{{ end }} - -{{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg")}} - {{ with . }} -
- {{ end }} -{{ else }} - {{ with .Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }} -
- {{ end }} -{{ end }} - -
+{{ with $backgroundImage }} + {{ if $shouldAddHeaderSpace | default true}} +
+ {{ end }} + {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} +
+
+ class="absolute inset-0 opacity-60 bg-gradient-to-t from-neutral dark:from-neutral-800 to-neutral-100 dark:to-neutral-800 mix-blend-normal">
-
-{{ if $shouldBlur | default false }} -
-{{ $backgroundBlur := resources.Get "js/background-blur.js" }} -{{ $backgroundBlur = $backgroundBlur | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }} - +
+ {{ if $shouldBlur | default false }} +
+ {{ $backgroundBlur := resources.Get "js/background-blur.js" }} + {{ $backgroundBlur = $backgroundBlur | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }} + + {{ end }} {{ end }} -{{- end -}} diff --git a/layouts/partials/hero/basic.html b/layouts/partials/hero/basic.html index 54e84ed3..de8e0882 100644 --- a/layouts/partials/hero/basic.html +++ b/layouts/partials/hero/basic.html @@ -1,37 +1,29 @@ -{{ $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 }} +{{ $images := .Resources.ByType "image" }} +{{ $backgroundImage := $images.GetMatch "*background*" }} +{{ if not $backgroundImage }} + {{ $backgroundImage := $images.GetMatch "*feature*" }} {{ end }} - -{{- if not $featured }} +{{ if not $backgroundImage }} + {{ $backgroundImage = $images.GetMatch "{*cover*,*thumbnail*}" }} +{{ end }} +{{ if and (not $backgroundImage) .Params.featureimage }} + {{ $backgroundImage = resources.GetRemote .Params.featureimage }} +{{ end }} +{{ if not $backgroundImage }} {{ with .Site.Params.defaultBackgroundImage }} {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} - {{ $featured = resources.GetRemote . }} + {{ $backgroundImage = resources.GetRemote . }} {{ else }} - {{ $featured = resources.Get . }} + {{ $backgroundImage = resources.Get . }} {{ end }} {{ end }} -{{ end -}} +{{ end }} +{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} +{{ if and ($backgroundImage) (not (or ($disableImageOptimization) (strings.HasSuffix $backgroundImage.Name ".svg"))) }} + {{ $backgroundImage = $backgroundImage.Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }} +{{ end }} -{{- with $featured -}} - {{ if or $disableImageOptimization (strings.HasSuffix $featured ".svg") }} - {{ with . }} -
- {{ end }} - {{ else }} - {{ with .Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }} -
- {{ end }} - {{ end }} -{{- end -}} +{{ with $backgroundImage }} + {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} +
+{{ end }} diff --git a/layouts/partials/hero/thumbAndBackground.html b/layouts/partials/hero/thumbAndBackground.html index 2a8448cb..841f83ec 100644 --- a/layouts/partials/hero/thumbAndBackground.html +++ b/layouts/partials/hero/thumbAndBackground.html @@ -1,98 +1,77 @@ -{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} - -{{- $images := .Resources.ByType "image" -}} -{{- $background := $images.GetMatch "*background*" -}} - -{{- if not $background }} +{{ $images := .Resources.ByType "image" }} +{{ $backgroundImage := $images.GetMatch "*background*" }} +{{ if not $backgroundImage }} {{ with .Site.Params.defaultBackgroundImage }} {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} - {{ $background = resources.GetRemote . }} + {{ $backgroundImage = resources.GetRemote . }} {{ else }} - {{ $background = resources.Get . }} + {{ $backgroundImage = 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 $backgroundImage }} + {{ $backgroundImage = $images.GetMatch "{*cover*,*thumbnail*}" }} +{{ end }} +{{ if not $backgroundImage }} + {{ $backgroundImage := $images.GetMatch "*feature*" }} +{{ end }} +{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} +{{ if and ($backgroundImage) (not (or ($disableImageOptimization) (strings.HasSuffix $backgroundImage.Name ".svg"))) }} + {{ $backgroundImage = $backgroundImage.Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }} +{{ end }} -{{- if not $featured }} +{{ $featuredImage := $images.GetMatch "*feature*" }} +{{ if not $featuredImage }} + {{ $featuredImage = $images.GetMatch "{*cover*,*thumbnail*}" }} +{{ end }} +{{ if and (not $featuredImage) .Params.featureimage }} + {{ $featuredImage = resources.GetRemote .Params.featureimage }} +{{ end }} +{{ if not $featuredImage }} + {{ $featuredImage = resources.Get .Site.Params.defaultFeaturedImage }} +{{ end }} +{{ if not $featuredImage }} + {{ $featuredImage := $images.GetMatch "*background*" }} +{{ end }} +{{ if not $featuredImage }} {{ with .Site.Params.defaultFeaturedImage }} {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} - {{ $featured = resources.GetRemote . }} + {{ $featuredImage = resources.GetRemote . }} {{ else }} - {{ $featured = resources.Get . }} + {{ $featuredImage = resources.Get . }} {{ end }} {{ end }} -{{ end -}} +{{ end }} +{{ if and ($featuredImage) (not (or ($disableImageOptimization) (strings.HasSuffix $featuredImage.Name ".svg"))) }} + {{ $featuredImage = $featuredImage.Resize "600x" }} +{{ end }} -{{ $isParentList := eq (.Scratch.Get "scope") "list" }} +{{ $isParentList := eq (.Scratch.Get "scope") "list" }} {{ $shouldBlur := $.Params.layoutBackgroundBlur | default (or - (and ($.Site.Params.article.layoutBackgroundBlur | default true) (not $isParentList)) - (and ($.Site.Params.list.layoutBackgroundBlur | default true) ($isParentList)) - ) -}} + (and ($.Site.Params.article.layoutBackgroundBlur | default true) (not $isParentList)) + (and ($.Site.Params.list.layoutBackgroundBlur | default true) ($isParentList)) + ) }} -{{- with $featured -}} - {{ if or $disableImageOptimization (strings.HasSuffix . ".svg") }} - {{ with . }} -
- {{ end }} - {{ else }} - {{ with .Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }} -
- {{ end }} - {{ end }} -{{- end -}} +{{ with $featuredImage }} + {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} +
+{{ end }} -{{- with $background -}} - - {{ if or $disableImageOptimization (strings.HasSuffix . ".svg") }} - {{ with . }} -
-
-
-
- {{ end }} - {{ else }} - {{ with .Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x") }} -
-
-
-
- {{ end }} - {{ end }} - -{{- end -}} +{{ with $backgroundImage }} + {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} +
+
+
+
+
+
+{{ end }} {{ if $shouldBlur | default false }} -
+
{{ $backgroundBlur := resources.Get "js/background-blur.js" }} - {{ $backgroundBlur = $backgroundBlur | resources.Minify | resources.Fingerprint (.Site.Params.fingerprintAlgorithm | default "sha512") }} - + {{ $backgroundBlur = $backgroundBlur | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }} + {{ end }} diff --git a/layouts/partials/term-link/card.html b/layouts/partials/term-link/card.html index 280a74d4..31fdc225 100644 --- a/layouts/partials/term-link/card.html +++ b/layouts/partials/term-link/card.html @@ -1,32 +1,29 @@
- {{ $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" }} + {{ $featuredImage := $images.GetMatch "*feature*" }} + {{ if not $featuredImage }} + {{ $featuredImage = $images.GetMatch "{*cover*,*thumbnail*}" }} + {{ end }} + {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} + {{ if and ($featuredImage) (not (or ($disableImageOptimization) (strings.HasSuffix $featuredImage.Name ".svg"))) }} + {{ $featuredImage = $featuredImage.Resize "600x" }} + {{ end }} + {{ with $featuredImage }} + {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} + + {{ else }} + {{ with site.Params.images }} + {{ end }} - {{- else -}} - {{- with site.Params.images }} - - {{ end -}} - {{- end -}} - {{- end -}} + {{ end }} + {{ end }} {{ if site.Params.taxonomy.showTermCount | default true }} From f82776c86bf959d181e0be6291140bce982be5a3 Mon Sep 17 00:00:00 2001 From: Served Smart <195884188+servedsmart@users.noreply.github.com> Date: Sun, 22 Jun 2025 04:21:38 +0200 Subject: [PATCH 2/3] :bug: Fix: Typos and images not in css if optimized --- layouts/partials/head.html | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 78509d3e..201fbcb8 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -47,29 +47,32 @@ {{ end }} {{ $images := slice }} - {{ $backgroundAndfeaturedImages := slice }} + {{ $backgroundAndFeaturedImages := slice }} {{ range .Site.Pages }} {{ $images = $images | append (.Page.Resources.ByType "image") }} {{ if .Params.featureimage }} - {{ $backgroundAndfeaturedImages = $backgroundAndfeaturedImages | append (resources.GetRemote .Params.featureimage) }} + {{ $backgroundAndFeaturedImages = $backgroundAndFeaturedImages | append (resources.GetRemote .Params.featureimage) }} {{ end }} {{ end }} - {{ $backgroundAndfeaturedImages = $backgroundAndfeaturedImages | append ($images.Match "{*background*,*feature*,*cover*,*thumbnail*}") }} + {{ $backgroundAndFeaturedImages = $backgroundAndFeaturedImages | append ($images.Match "{*background*,*feature*,*cover*,*thumbnail*}") }} {{ $siteParams := slice .Site.Params.defaultFeaturedImage .Site.Params.defaultBackgroundImage }} {{ range $siteParams }} {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} - {{ $backgroundAndfeaturedImages = $backgroundAndfeaturedImages | append (resources.GetRemote .) }} + {{ $backgroundAndFeaturedImages = $backgroundAndFeaturedImages | append (resources.GetRemote .) }} {{ else }} - {{ $backgroundAndfeaturedImages = $backgroundAndfeaturedImages | append (resources.Get .) }} + {{ $backgroundAndFeaturedImages = $backgroundAndFeaturedImages | append (resources.Get .) }} {{ end }} {{ end }} {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} - {{ range $backgroundAndfeaturedImages }} - {{ $backgroundAndfeaturedImages := . }} - {{ if not (or ($disableImageOptimization) (strings.HasSuffix .Name ".svg")) }} - {{ $backgroundAndfeaturedImages = .Resize "600x" }} + {{ range $backgroundAndFeaturedImages }} + {{ $images := slice }} + {{ if or $disableImageOptimization (strings.HasSuffix .Name ".svg") }} + {{ $images = $images | append . }} + {{ else }} + {{ $images = $images | append (.Resize "600x") }} + {{ $images = $images | append (.Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x")) }} {{ end }} - {{ with $backgroundAndfeaturedImages }} + {{ range $images }} {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} {{ $cssBackgroundImage := printf ".%s { background-image: url(\"%s\"); }" $className .RelPermalink }} {{ $cssBackgroundImage = $cssBackgroundImage | resources.FromString "css/background-image.css" }} From 80486364cdd8d94be01d840f2729f0b943ae152f Mon Sep 17 00:00:00 2001 From: Served Smart <195884188+servedsmart@users.noreply.github.com> Date: Mon, 23 Jun 2025 02:26:39 +0200 Subject: [PATCH 3/3] :bug: Fix: Reassignment of variable names I'm not sure why this is such a big problem, but hugo doesn't seem to like this. It is also better to just use the intended way to reassign vars always. Before, *feature* images if using background.html would always get overwritten, now that is fixed. --- layouts/partials/head.html | 10 +++++----- layouts/partials/hero/background.html | 2 +- layouts/partials/hero/basic.html | 2 +- layouts/partials/hero/thumbAndBackground.html | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 201fbcb8..95f6dade 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -65,14 +65,14 @@ {{ end }} {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} {{ range $backgroundAndFeaturedImages }} - {{ $images := slice }} + {{ $classImages := slice }} {{ if or $disableImageOptimization (strings.HasSuffix .Name ".svg") }} - {{ $images = $images | append . }} + {{ $classImages = $classImages | append . }} {{ else }} - {{ $images = $images | append (.Resize "600x") }} - {{ $images = $images | append (.Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x")) }} + {{ $classImages = $classImages | append (.Resize "600x") }} + {{ $classImages = $classImages | append (.Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x")) }} {{ end }} - {{ range $images }} + {{ range $classImages }} {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} {{ $cssBackgroundImage := printf ".%s { background-image: url(\"%s\"); }" $className .RelPermalink }} {{ $cssBackgroundImage = $cssBackgroundImage | resources.FromString "css/background-image.css" }} diff --git a/layouts/partials/hero/background.html b/layouts/partials/hero/background.html index 674df3c8..7faae0d9 100644 --- a/layouts/partials/hero/background.html +++ b/layouts/partials/hero/background.html @@ -1,7 +1,7 @@ {{ $images := .Resources.ByType "image" }} {{ $backgroundImage := $images.GetMatch "*background*" }} {{ if not $backgroundImage }} - {{ $backgroundImage := $images.GetMatch "*feature*" }} + {{ $backgroundImage = $images.GetMatch "*feature*" }} {{ end }} {{ if not $backgroundImage }} {{ $backgroundImage = $images.GetMatch "{*cover*,*thumbnail*}" }} diff --git a/layouts/partials/hero/basic.html b/layouts/partials/hero/basic.html index de8e0882..2123652c 100644 --- a/layouts/partials/hero/basic.html +++ b/layouts/partials/hero/basic.html @@ -1,7 +1,7 @@ {{ $images := .Resources.ByType "image" }} {{ $backgroundImage := $images.GetMatch "*background*" }} {{ if not $backgroundImage }} - {{ $backgroundImage := $images.GetMatch "*feature*" }} + {{ $backgroundImage = $images.GetMatch "*feature*" }} {{ end }} {{ if not $backgroundImage }} {{ $backgroundImage = $images.GetMatch "{*cover*,*thumbnail*}" }} diff --git a/layouts/partials/hero/thumbAndBackground.html b/layouts/partials/hero/thumbAndBackground.html index 841f83ec..ca83ff88 100644 --- a/layouts/partials/hero/thumbAndBackground.html +++ b/layouts/partials/hero/thumbAndBackground.html @@ -13,7 +13,7 @@ {{ $backgroundImage = $images.GetMatch "{*cover*,*thumbnail*}" }} {{ end }} {{ if not $backgroundImage }} - {{ $backgroundImage := $images.GetMatch "*feature*" }} + {{ $backgroundImage = $images.GetMatch "*feature*" }} {{ end }} {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} {{ if and ($backgroundImage) (not (or ($disableImageOptimization) (strings.HasSuffix $backgroundImage.Name ".svg"))) }} @@ -31,7 +31,7 @@ {{ $featuredImage = resources.Get .Site.Params.defaultFeaturedImage }} {{ end }} {{ if not $featuredImage }} - {{ $featuredImage := $images.GetMatch "*background*" }} + {{ $featuredImage = $images.GetMatch "*background*" }} {{ end }} {{ if not $featuredImage }} {{ with .Site.Params.defaultFeaturedImage }} @@ -53,13 +53,13 @@ ) }} {{ with $featuredImage }} - {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} -
+ {{ $classNameFeaturedImage := printf "background-image-%s" (md5 .RelPermalink) }} +
{{ end }} {{ with $backgroundImage }} - {{ $className := printf "background-image-%s" (md5 .RelPermalink) }} -
+ {{ $classNameBackgroundImage := printf "background-image-%s" (md5 .RelPermalink) }} +