mirror of
https://github.com/m1ngsama/FUJI.git
synced 2025-12-25 02:56:38 +00:00
20 lines
574 B
TypeScript
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)
|
|
}
|
|
}
|