Fix minimal details

This commit is contained in:
prototypa
2022-09-04 00:56:24 -04:00
parent 570cf904c4
commit 1cf25d6b43
44 changed files with 757 additions and 641 deletions

35
src/utils/images.js Normal file
View File

@@ -0,0 +1,35 @@
const load = async function () {
let images = [];
try {
images = import.meta.glob("~/assets/images/*");
} catch (e) {}
return images;
};
let _images;
/** */
export const fetchLocalImages = async () => {
_images = _images || load();
return await _images;
};
/** */
export const findImage = async (imagePath) => {
if (typeof imagePath !== "string") {
return null;
}
if (imagePath.startsWith("http://") || imagePath.startsWith("https://")) {
return imagePath;
}
if (!imagePath.startsWith("~/assets")) {
return null;
} // For now only consume images using ~/assets alias (or absolute)
const images = await fetchLocalImages();
const key = imagePath.replace("~/", "/src/");
return typeof images[key] === "function" ? (await images[key]())["default"] : null;
};