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 1
1
---
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
+
2
9
type Props = {
3
10
sponsor: {
4
11
rank: " platinum" | " gold" | " silver" | " bronze" ;
@@ -11,14 +18,14 @@ type Props = {
11
18
const props = Astro .props ;
12
19
const { rank, name, url, image } = props .sponsor ;
13
20
21
+ const imagePath = ` /src/assets/sponsors/${image } ` ;
14
22
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 } ` );
22
29
}
23
30
24
31
// ランクごとのスタイル設定
You can’t perform that action at this time.
0 commit comments