Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 4 additions & 26 deletions src/components/cloudinary/CloudinaryImg.astro
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,21 @@ interface Props extends CloudinaryProps {
class?: string;
svg?: boolean;
id?: string;
width?: number;
height?: number;
}

const { src: initialSrc, class: className, width, height, alt, id } = Astro.props;
const { src: initialSrc, ...props } = Astro.props;

let src = initialSrc;
if (!src.startsWith("https://")) {
src = getCloudinarySrc({ ...Astro.props, src: initialSrc });
src = getCloudinarySrc({ ...props, src: initialSrc });
}

const url = src;
const isRemote = url.startsWith("http://") || url.startsWith("https://");
// Ensure URL is safe for HTML src (e.g. Cloudinary URLs with & in query params)
const srcAttr = isRemote ? url.replace(/&/g, "&") : url;
---

{isRemote ? (
<img
src={srcAttr}
alt={alt}
width={width}
height={height}
class={className}
id={id}
loading="lazy"
decoding="async"
/>
<img src={url} loading="lazy" decoding="async" {...props} />
) : (
<Image
src={url}
alt={alt}
loading="lazy"
inferSize={true}
width={width}
height={height}
class={className}
id={id}
/>
<Image src={url} loading="lazy" inferSize={true} {...props} />
)}