🐛 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.
This commit is contained in:
Served Smart
2025-06-23 02:26:39 +02:00
parent f82776c86b
commit 80486364cd
4 changed files with 13 additions and 13 deletions

View File

@@ -65,14 +65,14 @@
{{ end }} {{ end }}
{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }}
{{ range $backgroundAndFeaturedImages }} {{ range $backgroundAndFeaturedImages }}
{{ $images := slice }} {{ $classImages := slice }}
{{ if or $disableImageOptimization (strings.HasSuffix .Name ".svg") }} {{ if or $disableImageOptimization (strings.HasSuffix .Name ".svg") }}
{{ $images = $images | append . }} {{ $classImages = $classImages | append . }}
{{ else }} {{ else }}
{{ $images = $images | append (.Resize "600x") }} {{ $classImages = $classImages | append (.Resize "600x") }}
{{ $images = $images | append (.Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x")) }} {{ $classImages = $classImages | append (.Resize (print ($.Site.Params.backgroundImageWidth | default "1200") "x")) }}
{{ end }} {{ end }}
{{ range $images }} {{ range $classImages }}
{{ $className := printf "background-image-%s" (md5 .RelPermalink) }} {{ $className := printf "background-image-%s" (md5 .RelPermalink) }}
{{ $cssBackgroundImage := printf ".%s { background-image: url(\"%s\"); }" $className .RelPermalink }} {{ $cssBackgroundImage := printf ".%s { background-image: url(\"%s\"); }" $className .RelPermalink }}
{{ $cssBackgroundImage = $cssBackgroundImage | resources.FromString "css/background-image.css" }} {{ $cssBackgroundImage = $cssBackgroundImage | resources.FromString "css/background-image.css" }}

View File

@@ -1,7 +1,7 @@
{{ $images := .Resources.ByType "image" }} {{ $images := .Resources.ByType "image" }}
{{ $backgroundImage := $images.GetMatch "*background*" }} {{ $backgroundImage := $images.GetMatch "*background*" }}
{{ if not $backgroundImage }} {{ if not $backgroundImage }}
{{ $backgroundImage := $images.GetMatch "*feature*" }} {{ $backgroundImage = $images.GetMatch "*feature*" }}
{{ end }} {{ end }}
{{ if not $backgroundImage }} {{ if not $backgroundImage }}
{{ $backgroundImage = $images.GetMatch "{*cover*,*thumbnail*}" }} {{ $backgroundImage = $images.GetMatch "{*cover*,*thumbnail*}" }}

View File

@@ -1,7 +1,7 @@
{{ $images := .Resources.ByType "image" }} {{ $images := .Resources.ByType "image" }}
{{ $backgroundImage := $images.GetMatch "*background*" }} {{ $backgroundImage := $images.GetMatch "*background*" }}
{{ if not $backgroundImage }} {{ if not $backgroundImage }}
{{ $backgroundImage := $images.GetMatch "*feature*" }} {{ $backgroundImage = $images.GetMatch "*feature*" }}
{{ end }} {{ end }}
{{ if not $backgroundImage }} {{ if not $backgroundImage }}
{{ $backgroundImage = $images.GetMatch "{*cover*,*thumbnail*}" }} {{ $backgroundImage = $images.GetMatch "{*cover*,*thumbnail*}" }}

View File

@@ -13,7 +13,7 @@
{{ $backgroundImage = $images.GetMatch "{*cover*,*thumbnail*}" }} {{ $backgroundImage = $images.GetMatch "{*cover*,*thumbnail*}" }}
{{ end }} {{ end }}
{{ if not $backgroundImage }} {{ if not $backgroundImage }}
{{ $backgroundImage := $images.GetMatch "*feature*" }} {{ $backgroundImage = $images.GetMatch "*feature*" }}
{{ end }} {{ end }}
{{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }} {{ $disableImageOptimization := .Page.Site.Params.disableImageOptimization | default false }}
{{ if and ($backgroundImage) (not (or ($disableImageOptimization) (strings.HasSuffix $backgroundImage.Name ".svg"))) }} {{ if and ($backgroundImage) (not (or ($disableImageOptimization) (strings.HasSuffix $backgroundImage.Name ".svg"))) }}
@@ -31,7 +31,7 @@
{{ $featuredImage = resources.Get .Site.Params.defaultFeaturedImage }} {{ $featuredImage = resources.Get .Site.Params.defaultFeaturedImage }}
{{ end }} {{ end }}
{{ if not $featuredImage }} {{ if not $featuredImage }}
{{ $featuredImage := $images.GetMatch "*background*" }} {{ $featuredImage = $images.GetMatch "*background*" }}
{{ end }} {{ end }}
{{ if not $featuredImage }} {{ if not $featuredImage }}
{{ with .Site.Params.defaultFeaturedImage }} {{ with .Site.Params.defaultFeaturedImage }}
@@ -53,13 +53,13 @@
) }} ) }}
{{ with $featuredImage }} {{ with $featuredImage }}
{{ $className := printf "background-image-%s" (md5 .RelPermalink) }} {{ $classNameFeaturedImage := printf "background-image-%s" (md5 .RelPermalink) }}
<div class="w-full rounded-md h-36 md:h-56 lg:h-72 single_hero_basic nozoom {{ $className }}"></div> <div class="w-full rounded-md h-36 md:h-56 lg:h-72 single_hero_basic nozoom {{ $classNameFeaturedImage }}"></div>
{{ end }} {{ end }}
{{ with $backgroundImage }} {{ with $backgroundImage }}
{{ $className := printf "background-image-%s" (md5 .RelPermalink) }} {{ $classNameBackgroundImage := printf "background-image-%s" (md5 .RelPermalink) }}
<div class="fixed inset-x-0 top-0 h-[800px] single_hero_background nozoom {{ $className }}"> <div class="fixed inset-x-0 top-0 h-[800px] single_hero_background nozoom {{ $classNameBackgroundImage }}">
<div <div
class="absolute inset-0 bg-gradient-to-t from-neutral dark:from-neutral-800 to-transparent mix-blend-normal"> class="absolute inset-0 bg-gradient-to-t from-neutral dark:from-neutral-800 to-transparent mix-blend-normal">
</div> </div>