fix: revert some of the last changes
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Deploy to SFTP Server / build (push) Successful in 16m52s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Deploy to SFTP Server / build (push) Successful in 16m52s
				
			This commit is contained in:
		| @@ -1,6 +1,7 @@ | |||||||
| --- | --- | ||||||
| import type { ImageMetadata } from "astro"; | import type { ImageMetadata } from "astro"; | ||||||
| import { Picture as AstroImage } from "astro:assets"; | import { Picture as AstroImage } from "astro:assets"; | ||||||
|  | import { inferRemoteSize } from "astro/assets/utils"; | ||||||
| import { generateThumbHash, getImageBuffer, getExifData } from "@helpers/image"; | import { generateThumbHash, getImageBuffer, getExifData } from "@helpers/image"; | ||||||
| interface Props { | interface Props { | ||||||
|   src: ImageMetadata & { fsPath?: string; src?: string }; |   src: ImageMetadata & { fsPath?: string; src?: string }; | ||||||
| @@ -13,6 +14,26 @@ interface Props { | |||||||
|   maxWidth?: number; |   maxWidth?: number; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | async function checkImage(image: ImageMetadata) { | ||||||
|  |   const src = typeof image === "string" ? image : image.src; | ||||||
|  |   if (!src) return false; | ||||||
|  |   try { | ||||||
|  |     if (src.startsWith("/@fs") || src.startsWith("/_astro")) return true; | ||||||
|  |     const res = await inferRemoteSize(src); | ||||||
|  |     if (res.format) { | ||||||
|  |       image.format = res.format; | ||||||
|  |       return true; | ||||||
|  |     } else { | ||||||
|  |       console.log("Failed to load: ", src); | ||||||
|  |     } | ||||||
|  |     return false; | ||||||
|  |   } catch (err) { | ||||||
|  |     console.log("\n"); | ||||||
|  |     console.log("Failed to fetch: ", src); | ||||||
|  |     return false; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
| const { | const { | ||||||
|   src: image, |   src: image, | ||||||
|   loader = true, |   loader = true, | ||||||
| @@ -22,7 +43,10 @@ const { | |||||||
|   maxWidth, |   maxWidth, | ||||||
| } = Astro.props; | } = Astro.props; | ||||||
|  |  | ||||||
| const imageBuffer = await getImageBuffer(image); |  | ||||||
|  |  | ||||||
|  | const imageOk = await checkImage(image); | ||||||
|  | const imageBuffer = imageOk && await getImageBuffer(image); | ||||||
| let thumbhash = imageBuffer && (await generateThumbHash(imageBuffer)); | let thumbhash = imageBuffer && (await generateThumbHash(imageBuffer)); | ||||||
| let exif = imageBuffer && (await getExifData(imageBuffer)); | let exif = imageBuffer && (await getExifData(imageBuffer)); | ||||||
|  |  | ||||||
| @@ -45,19 +69,23 @@ const sizes = [ | |||||||
| ].filter((size) => !maxWidth || size.width <= maxWidth); | ].filter((size) => !maxWidth || size.width <= maxWidth); | ||||||
| --- | --- | ||||||
|  |  | ||||||
| <AstroImage | { | ||||||
|   src={image} |   imageOk ? ( | ||||||
|   alt={alt} |     <AstroImage | ||||||
|   data-thumbhash={thumbhash} |       src={image} | ||||||
|   data-exif={JSON.stringify(exif)} |       alt={alt} | ||||||
|   inferSize={true} |       data-thumbhash={thumbhash} | ||||||
|   pictureAttributes={{ |       data-exif={JSON.stringify(exif)} | ||||||
|     class: `${hash ? "block h-full relative" : ""} ${loader ? "thumb" : ""} ${pictureClass}`, |       inferSize={true} | ||||||
|   }} |       pictureAttributes={{ | ||||||
|   class={Astro.props.class} |         class: `${hash ? "block h-full relative" : ""} ${loader ? "thumb" : ""} ${pictureClass}`, | ||||||
|   widths={sizes.map((size) => size.width)} |       }} | ||||||
|   sizes={sizes |       class={Astro.props.class} | ||||||
|     .map((size) => `${size.media || "100vw"} ${size.width}px`) |       widths={sizes.map((size) => size.width)} | ||||||
|     .join(", ")}> |       sizes={sizes | ||||||
|   <slot /> |         .map((size) => `${size.media || "100vw"} ${size.width}px`) | ||||||
| </AstroImage> |         .join(", ")}> | ||||||
|  |       <slot /> | ||||||
|  |     </AstroImage> | ||||||
|  |   ) : undefined | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user