diff --git a/src/utils/findImage.js b/src/utils/findImage.js new file mode 100644 index 0000000..ba102d2 --- /dev/null +++ b/src/utils/findImage.js @@ -0,0 +1,17 @@ +export const findImage = async (imageRoute) => { + const images = import.meta.glob("../assets/images/*"); + + const key = imageRoute.replace("~/", "../"); + + const image = + typeof imageRoute === "string" && + (imageRoute.startsWith("/") || + imageRoute.startsWith("http://") || + imageRoute.startsWith("https://")) + ? imageRoute + : typeof images[key] === "function" + ? (await images[key]())["default"] + : null; + + return image; +};