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}`); } // ランクごとのスタイル設定