feat(image): enhance image handling with new properties and responsive support
- 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:
@@ -143,7 +143,7 @@ export interface ResponsiveImageOptions {
|
||||
}
|
||||
|
||||
const DEFAULT_WIDTHS = [640, 960, 1280, 1600, 1920, 2400];
|
||||
const DEFAULT_FORMATS: Array<'avif' | 'webp' | 'jpeg'> = ['avif', 'webp', 'jpeg'];
|
||||
const DEFAULT_FORMATS: Array<'avif' | 'webp' | 'jpeg'> = ['webp', 'jpeg'];
|
||||
const MIME_FOR_FORMAT: Record<'avif' | 'webp' | 'jpeg', string> = {
|
||||
avif: 'image/avif',
|
||||
webp: 'image/webp',
|
||||
@@ -232,3 +232,26 @@ export async function buildResponsiveImage(
|
||||
...(lqip ? { lqip } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire-and-forget Cache-Warmup: alle srcset-Varianten + Fallback parallel anrequesten.
|
||||
* Nutzt SvelteKit's `event.fetch` für Self-Calls (keine echten HTTP-Roundtrips in Prod-SSR).
|
||||
* Blockiert den Response NICHT — läuft im Hintergrund weiter.
|
||||
*/
|
||||
export function warmResponsiveImage(
|
||||
responsive: ResponsiveImage | null,
|
||||
fetchFn: typeof fetch,
|
||||
): void {
|
||||
if (!responsive) return;
|
||||
const urls = new Set<string>();
|
||||
urls.add(responsive.fallback);
|
||||
for (const s of responsive.sources) {
|
||||
for (const entry of s.srcset.split(',')) {
|
||||
const url = entry.trim().split(/\s+/)[0];
|
||||
if (url) urls.add(url);
|
||||
}
|
||||
}
|
||||
for (const u of urls) {
|
||||
void fetchFn(u).catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user