From f8befe62cc1472d550d1c04d394e33e1f542d70b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernat=20Borr=C3=A0s=20Civil?= <70479573+BernatBC@users.noreply.github.com> Date: Tue, 28 Jan 2025 15:59:47 +0100 Subject: [PATCH] Add dark background (#1024) Co-authored-by: Emruz Hossain --- layouts/partials/sections/home.html | 67 +++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/layouts/partials/sections/home.html b/layouts/partials/sections/home.html index 9dddf46..3f244a2 100644 --- a/layouts/partials/sections/home.html +++ b/layouts/partials/sections/home.html @@ -20,6 +20,10 @@ {{ $backgroundImage = site.Params.background }} {{ end }} +{{ $darkBackgroundImage:= $backgroundImage }} +{{ if site.Params.darkBackground }} + {{ $darkBackgroundImage = site.Params.darkBackground }} +{{ end }} {{ $authorImage:= "/images/default-avatar.png" }} {{ if $author.image }} @@ -73,6 +77,41 @@ {{ $large := $src}} {{ end }} +{{/* get file that matches the filename as specified as src="" in shortcode */}} +{{ $darkSrc := resources.Get $darkBackgroundImage }} + +{{/* resize the src image to the given sizes */}} + +{{ $darkTiny := $darkSrc.Resize $tinyw }} +{{ $darkSmall := $darkSrc.Resize $smallw }} +{{ $darkMedium := $darkSrc.Resize $mediumw }} +{{ $darkLarge := $darkSrc.Resize $largew }} + +{{/* only use images smaller than or equal to the src (original) image size, as Hugo will upscale small images */}} +{{/* set the sizes attribute to (min-width: 35em) 1200px, 100vw unless overridden in shortcode */}} + +{{ if lt $darkSrc.Width "500" }} + {{ $darkTiny := $src}} + {{ $darkSmall := $src}} + {{ $darkMedium := $src}} + {{ $darkLarge := $src}} +{{ end }} + +{{ if lt $src.Width "800" }} + {{ $darkSmall := $src}} + {{ $darkMedium := $src}} + {{ $darkLarge := $src}} +{{ end }} + +{{ if lt $src.Width "1200" }} + {{ $darkMedium := $src}} + {{ $darkLarge := $src}} +{{ end }} + +{{ if lt $src.Width "1500" }} + {{ $darkLarge := $src}} +{{ end }} +