Skip to content

Commit a92ac2c

Browse files
committed
add youtube player
1 parent f01a858 commit a92ac2c

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

src/lib/components/ui/card/ProjectCard.svelte

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
<script lang="ts">
22
import type { Post } from '$lib/model';
3+
import Spinner from '../polish/spinner/Spinner.svelte';
34
45
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+
}
521
</script>
622

723
<a
@@ -11,19 +27,23 @@
1127
<div class="flex h-64 flex-col">
1228
{#if post.youtubeURL != undefined}
1329
<iframe
14-
class="flex flex-grow"
15-
src="https://www.youtube-nocookie.com/embed/oIzACzUwmVM?si=xU_cO-6pQfrxR2pp&amp;controls=0"
30+
class="flex aspect-video flex-grow"
31+
src="{post.youtubeURL}&amp;controls=0"
1632
title="YouTube video player"
1733
frameborder="0"
1834
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
1935
referrerpolicy="strict-origin-when-cross-origin"
2036
allowfullscreen
2137
></iframe>
2238
{: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}
2747
{/if}
2848

2949
<div class="bottom-0 grid min-h-[3lh] grid-cols-5 bg-black/50 p-2">

0 commit comments

Comments
 (0)