From 8fb99ab3e1b7cac334a6db27001a571b23186105 Mon Sep 17 00:00:00 2001 From: staticWagomU Date: Thu, 14 Aug 2025 21:32:23 +0900 Subject: [PATCH] =?UTF-8?q?fix(Sponsors):=20import.meta.glob=E3=82=92?= =?UTF-8?q?=E4=BD=BF=E3=81=A3=E3=81=A6=E7=94=BB=E5=83=8F=E3=83=91=E3=82=B9?= =?UTF-8?q?=E3=82=92=E5=8F=96=E5=BE=97=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2025/src/components/Sponsors/Company.astro | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/2025/src/components/Sponsors/Company.astro b/2025/src/components/Sponsors/Company.astro index f04fcf4d..d5327165 100644 --- a/2025/src/components/Sponsors/Company.astro +++ b/2025/src/components/Sponsors/Company.astro @@ -1,4 +1,11 @@ --- +import type { ImageMetadata } from "astro"; + +// import.meta.globで画像をlazyロード +const images = import.meta.glob<{ default: ImageMetadata }>( + "/src/assets/sponsors/*.{png,svg}", +); + type Props = { sponsor: { rank: "platinum" | "gold" | "silver" | "bronze"; @@ -11,14 +18,14 @@ type Props = { const props = Astro.props; const { rank, name, url, image } = props.sponsor; +const imagePath = `/src/assets/sponsors/${image}`; let imageUrl = ""; -try { - const module = await import( - /* @vite-ignore */ `../../assets/sponsors/${image}?url` - ); - imageUrl = module.default; -} catch (e) { - console.error(`Icon not found: ${image}`); + +if (images[imagePath]) { + const imageModule = await images[imagePath](); + imageUrl = imageModule.default.src; +} else { + console.error(`Image not found: ${imagePath}`); } // ランクごとのスタイル設定