veza/apps/web/src/components/ui/optimized-image/generateImageSources.ts

21 lines
441 B
TypeScript
Raw Normal View History

import { SUPPORTED_FORMATS } from './types';
export interface ImageSource {
src: string;
type: string;
sizes: string;
}
export function generateImageSources(
src: string,
sizes?: string,
): ImageSource[] {
const baseUrl = src.replace(/\.[^/.]+$/, '');
const sizesVal = sizes ?? '100vw';
return SUPPORTED_FORMATS.map((format) => ({
src: `${baseUrl}.${format}`,
type: `image/${format}`,
sizes: sizesVal,
}));
}