Add utils for consume image from assets
This commit is contained in:
17
src/utils/findImage.js
Normal file
17
src/utils/findImage.js
Normal file
@ -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;
|
||||||
|
};
|
Reference in New Issue
Block a user