feat: load data from marka
This commit is contained in:
@@ -13,6 +13,19 @@ interface Props {
|
||||
maxWidth?: number;
|
||||
}
|
||||
|
||||
async function checkImage(src:string){
|
||||
try {
|
||||
const res = await fetch(src);
|
||||
if (res.ok) {
|
||||
return src
|
||||
}
|
||||
return undefined
|
||||
}catch(err){
|
||||
console.log({src});
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
src: image,
|
||||
loader = true,
|
||||
@@ -24,6 +37,8 @@ const {
|
||||
|
||||
let thumbhash = hash && image.fsPath ? await generateThumbHash(image) : "";
|
||||
|
||||
const imageSrc = await checkImage(image);
|
||||
|
||||
let exif = await getExifData(image);
|
||||
|
||||
const sizes = [
|
||||
@@ -45,11 +60,13 @@ const sizes = [
|
||||
].filter((size) => !maxWidth || size.width <= maxWidth);
|
||||
---
|
||||
|
||||
{imageSrc?
|
||||
<AstroImage
|
||||
src={image}
|
||||
src={imageSrc}
|
||||
alt={alt}
|
||||
data-thumbhash={thumbhash}
|
||||
data-exif={JSON.stringify(exif)}
|
||||
inferSize={true}
|
||||
pictureAttributes={{
|
||||
class: `${hash ? "block h-full relative" : ""} ${loader ? "thumb" : ""} ${pictureClass}`,
|
||||
}}
|
||||
@@ -60,3 +77,4 @@ const sizes = [
|
||||
.join(", ")}>
|
||||
<slot />
|
||||
</AstroImage>
|
||||
:undefined }
|
||||
|
Reference in New Issue
Block a user