File tree 1 file changed +26
-6
lines changed
src/lib/components/ui/card 1 file changed +26
-6
lines changed Original file line number Diff line number Diff line change 1
1
<script lang =" ts" >
2
2
import type { Post } from ' $lib/model' ;
3
+ import Spinner from ' ../polish/spinner/Spinner.svelte' ;
3
4
4
5
export let post: Post ;
6
+
7
+ async function getImageSource(slug : string ) {
8
+ const path = ` /projects/${slug }/${slug } ` ;
9
+ const gifPath = ` ${path }.gif ` ;
10
+ const pngPath = ` ${path }.png ` ;
11
+
12
+ // Check if the gif exists
13
+
14
+ const gifExists = await fetch (gifPath )
15
+ .then ((res ) => res .ok )
16
+ .catch (() => false );
17
+
18
+ if (gifExists ) return gifPath ;
19
+ return pngPath ;
20
+ }
5
21
</script >
6
22
7
23
<a
11
27
<div class =" flex h-64 flex-col" >
12
28
{#if post .youtubeURL != undefined }
13
29
<iframe
14
- class =" flex flex-grow"
15
- src =" https://www.youtube-nocookie.com/embed/oIzACzUwmVM?si=xU_cO-6pQfrxR2pp & controls=0"
30
+ class =" flex aspect-video flex-grow"
31
+ src =" { post . youtubeURL } &controls=0"
16
32
title =" YouTube video player"
17
33
frameborder =" 0"
18
34
allow =" accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
19
35
referrerpolicy =" strict-origin-when-cross-origin"
20
36
allowfullscreen
21
37
></iframe >
22
38
{:else }
23
- <div
24
- class =" flex flex-grow"
25
- style ="background-image:url(/headers/ {post .slug }.png); background-size: cover"
26
- ></div >
39
+ {#await getImageSource (post .slug )}
40
+ <Spinner />
41
+ {:then source }
42
+ <div
43
+ class =" flex flex-grow"
44
+ style ="background-image:url( {source }); background-size: cover"
45
+ ></div >
46
+ {/await }
27
47
{/if }
28
48
29
49
<div class =" bottom-0 grid min-h-[3lh] grid-cols-5 bg-black/50 p-2" >
You can’t perform that action at this time.
0 commit comments