Skip to content

Commit

Permalink
Update VideoPlayer.astro
Browse files Browse the repository at this point in the history
  • Loading branch information
vincanger committed Jan 7, 2025
1 parent 53aad1b commit 8aff40f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions opensaas-sh/blog/src/components/VideoPlayer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ interface Props {
const { src, lgWidth = '55%', smWidth = '100%' } = Astro.props;
// Function to check if the URL is a YouTube URL and extract the video ID
// Function to check if the URL is a YouTube URL and, if so, extract the video ID
function getYouTubeId(url: string): string | null {
const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*/;
const match = url.match(regExp);
return match && match[2].length === 11 ? match[2] : null;
return match && match[2].length === 11 ? match[2] : null; // Note: all YouTube video IDs are 11 characters long.
}
const youtubeId = getYouTubeId(src);
const isYouTube = !!youtubeId;
const youTubeId = getYouTubeId(src);
const isYouTube = !!youTubeId;
---

{isYouTube ? (
<iframe
src={`https://www.youtube.com/embed/${youtubeId}`}
src={`https://www.youtube.com/embed/${youTubeId}`}
title="YouTube video player"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen
Expand Down

0 comments on commit 8aff40f

Please sign in to comment.