import { asset } from "$fresh/runtime.ts"; import * as CSS from "https://esm.sh/csstype@3.1.2"; interface ResponsiveAttributes { srcset: string; sizes: string; } function generateResponsiveAttributes( imageUrl: string, widths: number[], baseApiUrl: string, sizes = "100vw", ): ResponsiveAttributes { const srcsets: string[] = []; for (const width of widths) { const apiUrl = `${baseApiUrl}?image=${imageUrl}&width=${width}`; srcsets.push(`${apiUrl} ${width}w`); } const srcset = srcsets.join(", "); return { srcset, sizes, }; } const widths = [320, 640, 960, 1280]; // List of widths for srcset const Image = ( props: { class: string; src: string; alt?: string; thumbnail?: string; fill?: boolean; width?: number | string; height?: number | string; style?: CSS.HtmlAttributes; }, ) => { const responsiveAttributes = generateResponsiveAttributes( props.src, widths, "/api/images", ); return ( {props.alt} ); }; export default Image;