File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed
Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change 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+
29type Props = {
310 sponsor: {
411 rank: " platinum" | " gold" | " silver" | " bronze" ;
@@ -11,14 +18,14 @@ type Props = {
1118const props = Astro .props ;
1219const { rank, name, url, image } = props .sponsor ;
1320
21+ const imagePath = ` /src/assets/sponsors/${image } ` ;
1422let 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// ランクごとのスタイル設定
You can’t perform that action at this time.
0 commit comments