Skip to content

Commit d4aef83

Browse files
authored
Merge pull request #204 from vim-jp/feature/2025/fix-company-image
企業スポンサーの画像パスを正しく取得
2 parents bdc55b0 + 8fb99ab commit d4aef83

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

2025/src/components/Sponsors/Company.astro

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
---
2+
import type { ImageMetadata } from "astro";
3+
4+
// import.meta.globで画像をlazyロード
5+
const images = import.meta.glob<{ default: ImageMetadata }>(
6+
"/src/assets/sponsors/*.{png,svg}",
7+
);
8+
29
type Props = {
310
sponsor: {
411
rank: "platinum" | "gold" | "silver" | "bronze";
@@ -11,14 +18,14 @@ type Props = {
1118
const props = Astro.props;
1219
const { rank, name, url, image } = props.sponsor;
1320
21+
const imagePath = `/src/assets/sponsors/${image}`;
1422
let imageUrl = "";
15-
try {
16-
const module = await import(
17-
/* @vite-ignore */ `../../assets/sponsors/${image}?url`
18-
);
19-
imageUrl = module.default;
20-
} catch (e) {
21-
console.error(`Icon not found: ${image}`);
23+
24+
if (images[imagePath]) {
25+
const imageModule = await images[imagePath]();
26+
imageUrl = imageModule.default.src;
27+
} else {
28+
console.error(`Image not found: ${imagePath}`);
2229
}
2330
2431
// ランクごとのスタイル設定

0 commit comments

Comments
 (0)