From e30f20e86a9dd9141616a4e7043c73b1024936de Mon Sep 17 00:00:00 2001 From: saicaca Date: Mon, 23 Oct 2023 19:12:51 +0800 Subject: [PATCH] fix: temporary solution for images dynamic import --- src/components/misc/ImageBox.astro | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/misc/ImageBox.astro b/src/components/misc/ImageBox.astro index d0aee2a..0e06739 100644 --- a/src/components/misc/ImageBox.astro +++ b/src/components/misc/ImageBox.astro @@ -1,4 +1,5 @@ --- +import path from "path"; interface Props { id?: string src: string; @@ -12,9 +13,12 @@ const className = Astro.props.class; const isLocal = !(src.startsWith('/') || src.startsWith('http') || src.startsWith('https') || src.startsWith('data:')); +// TODO temporary workaround for images dynamic import let img; if (isLocal) { - img = (await import("../../" + src)).default; + const files = import.meta.glob("../../**", { import: 'default' }); + let normalizedPath = "../../" + path.normalize(src).replace(/\\/g, "/"); + img = await (files[normalizedPath])(); } --- @@ -22,6 +26,5 @@ if (isLocal) {
{isLocal && {alt} {!isLocal && {alt} -