11---
22import { Icon } from " astro-icon/components" ;
3- import normaAvatar1 from " ../../assets/images/norma-1.mp4" ;
4- import normaAvatar2 from " ../../assets/images/norma-2.mp4" ;
53import { profileConfig } from " ../../config" ;
64import { url } from " ../../utils/url-utils" ;
75import ImageWrapper from " ../misc/ImageWrapper.astro" ;
86
97const config = profileConfig ;
10- const avatars = [config .avatar || " " ].flat ().filter (Boolean );
11- const avatar = avatars [0 ] || " " ;
12- const isVideoAvatar =
13- avatars .length > 0 &&
14- avatars .every ((item ) => / \. (mp4| webm| ogg)([?#] . * )? $ / i .test (item ));
158
16- const localVideoAssets = new Map ([
17- [" assets/images/norma-1.mp4" , normaAvatar1 ],
18- [" assets/images/norma-2.mp4" , normaAvatar2 ],
19- ]);
20- const avatarVideoSrcList = [];
21- for (const item of avatars ) {
22- if (! isVideoAvatar ) {
23- break ;
24- }
9+ const avatar = config .avatar || " " ;
10+ const avatarVideos = config .avatarVideos ?? [];
11+ const videoAssets = import .meta .glob <{ default: string }>(" ../../assets/images/*.{mp4,webm,ogg}" , {
12+ eager: true ,
13+ });
2514
15+ function resolveAvatarSrc(item : string ) {
2616 const isLocalAvatar =
2717 ! item .startsWith (" /" ) &&
2818 ! item .startsWith (" http://" ) &&
2919 ! item .startsWith (" https://" ) &&
3020 ! item .startsWith (" data:" );
31- let src = item ;
32- if (isLocalAvatar ) {
33- const asset = localVideoAssets .get (item );
34- if (! asset ) {
35- console .error (` \n [ERROR] Video file not found: src/${item }` );
36- continue ;
37- }
38- src = asset ;
21+ if (! isLocalAvatar ) return item .startsWith (" /" ) ? url (item ) : item ;
22+
23+ const asset = videoAssets [` ../../${item } ` ];
24+ if (! asset ) {
25+ console .error (` \n [ERROR] Video file not found: src/${item }` );
26+ return " " ;
3927 }
40- avatarVideoSrcList . push ( src . startsWith ( " / " ) ? url ( src ) : src ) ;
28+ return asset . default ;
4129}
30+
31+ const avatarVideoSrcList = avatarVideos .map (resolveAvatarSrc ).filter (Boolean );
32+
33+ const hasAvatarVideos = avatarVideoSrcList .length > 0 ;
34+
35+ const isVideoAvatar =
36+ typeof avatar === " string" && / \. (mp4| webm| ogg)([?#] . * )? $ / i .test (avatar );
37+ const avatarVideoSrc = isVideoAvatar ? resolveAvatarSrc (avatar ) : " " ;
4238---
4339<div class =" card-base p-3" >
4440 <a aria-label =" Go to About Page" href ={ url (' /about/' )}
@@ -50,16 +46,34 @@ for (const item of avatars) {
5046 class =" transition opacity-0 scale-90 group-hover:scale-100 group-hover:opacity-100 text-white text-5xl" >
5147 </Icon >
5248 </div >
53- { isVideoAvatar && <video
54- src = { avatarVideoSrcList [0 ]}
55- data-avatar-videos = { JSON .stringify (avatarVideoSrcList )}
56- autoplay
57- loop
58- muted
59- playsinline
60- class = " mx-auto lg:w-full h-full lg:mt-0 object-cover aspect-square"
61- ></video >}
62- { ! isVideoAvatar && <ImageWrapper src = { avatar } class = " mx-auto lg:w-full h-full lg:mt-0 object-cover aspect-square" alt = { config .name } />}
49+ {
50+ hasAvatarVideos ? (
51+ <video
52+ src = { avatarVideoSrcList [0 ]}
53+ data-avatar-videos = { JSON .stringify (avatarVideoSrcList )}
54+ autoplay
55+ loop
56+ muted
57+ playsinline
58+ class = " mx-auto lg:w-full h-full lg:mt-0 object-cover aspect-square"
59+ />
60+ ) : avatarVideoSrc ? (
61+ <video
62+ src = { avatarVideoSrc }
63+ autoplay
64+ loop
65+ muted
66+ playsinline
67+ class = " mx-auto lg:w-full h-full lg:mt-0 object-cover aspect-square"
68+ />
69+ ) : (
70+ <ImageWrapper
71+ src = { avatar }
72+ class = " mx-auto lg:w-full h-full lg:mt-0 object-cover aspect-square"
73+ alt = { config .name }
74+ />
75+ )
76+ }
6377 </a >
6478 <div class =" px-2" >
6579 <div class =" font-bold text-xl text-center mb-1 dark:text-neutral-50 transition" >{ config .name } </div >
0 commit comments