FUJI/src/utils/image.ts
2024-09-22 20:41:33 +08:00

20 lines
574 B
TypeScript

import { getImage } from "astro:assets"
export async function fixImage(image: string, href: string) {
try {
const sliceHref = href.slice(0, href.lastIndexOf("/") + 1)// get the dir of the current page(remove filename)
const imageLocation = await import(
/* @vite-ignore */ `/src/pages${sliceHref}${image.slice(1)}`
)// static import of the image
image = imageLocation.default
return (
await getImage({ // resolve the images
src: image,
inferSize: true,
})
).src
}
catch (error) {
console.log(error)
}
}