Skip to content

Commit daff9a7

Browse files
committed
fix video regex issue
1 parent 915a582 commit daff9a7

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎apps/codingcatdev/src/lib/components/content/Video.svelte‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
export let src: string;
33
export let title: string;
44
5-
$: finalSrc = `https://www.youtube.com/embed/${src.split('/').at(-1)}`;
5+
const youtubeParser = (url: string) => {
6+
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
7+
var match = url.match(regExp);
8+
return match && match[7].length == 11 ? match[7] : false;
9+
};
10+
11+
$: finalSrc = `https://www.youtube.com/embed/${youtubeParser(src)}`;
612
</script>
713

814
<div class="aspect-video">

0 commit comments

Comments
 (0)