feat(image): enhance image handling with new properties and responsive support
Deploy / verify (push) Successful in 41s
Deploy / deploy (push) Successful in 1m2s

- Updated PostEntry type to include _rawImageUrl and _imageFocal for improved image management.
- Refactored image handling in various components to utilize the new properties, ensuring better focal point support and responsive image rendering.
- Introduced warmResponsiveImage function for pre-fetching image variants to optimize loading performance.
- Replaced CmsImage component with RustyImage in multiple blocks for consistent image processing.
This commit is contained in:
Peter Meier
2026-04-18 08:43:17 +02:00
parent 3c6ff773ae
commit a2f2d5bfb0
14 changed files with 297 additions and 162 deletions
@@ -7,7 +7,8 @@
import Icon from "@iconify/svelte";
import { useTranslate } from "$lib/translations";
import { T } from "$lib/translations";
import CmsImage from "$lib/components/CmsImage.svelte";
import RustyImage from "$lib/components/RustyImage.svelte";
import { extractCmsImageField } from "$lib/rusty-image";
const t = useTranslate();
let { block }: { block: ImageGalleryBlockData } = $props();
@@ -26,27 +27,24 @@
const withUrl = $derived(
images
.map((img) => {
const url = imageUrl(img);
return url != null ? { img, url } : null;
const field = extractCmsImageField(img);
return field?.url
? { img, url: field.url, focal: field.focal ?? null }
: null;
})
.filter((x): x is { img: ImageGalleryImage; url: string } => x != null),
.filter(
(
x,
): x is {
img: ImageGalleryImage;
url: string;
focal: { x: number; y: number } | null;
} => x != null,
),
);
let currentIndex = $state(0);
function imageUrl(img: ImageGalleryImage): string | null {
if (typeof img.src === "string") {
const s = img.src.trim();
if (!s) return null;
return s.startsWith("//") ? `https:${s}` : s;
}
if (img.file?.url) {
const u = img.file.url;
return u.startsWith("//") ? `https:${u}` : u;
}
return null;
}
function prev() {
currentIndex = (currentIndex - 1 + withUrl.length) % withUrl.length;
}
@@ -122,12 +120,12 @@
<p class="text-sm text-stein-500">{t(T.image_gallery_empty)}</p>
{:else if withUrl.length === 1}
<figure class="m-0">
<CmsImage
<RustyImage
src={withUrl[0].url}
focal={withUrl[0].focal}
width={1280}
height={720}
aspect="16/9"
fit="cover"
format="webp"
quality={80}
alt={withUrl[0].img.description ?? ""}
class="w-full rounded-sm object-cover aspect-video"
@@ -158,12 +156,12 @@
class="m-0 absolute inset-0"
transition:fade={{ duration: 200 }}
>
<CmsImage
<RustyImage
src={current.url}
focal={current.focal}
width={1280}
height={720}
aspect="16/9"
fit="cover"
format="webp"
quality={80}
alt={current.img.description ?? ""}
class="w-full h-full object-cover"