diff --git a/YouTubePlaylist.astro b/YouTubePlaylist.astro new file mode 100644 index 0000000..4d246b6 --- /dev/null +++ b/YouTubePlaylist.astro @@ -0,0 +1,62 @@ +--- +interface Props extends Omit { + class?: string + cookie?: boolean + embedParams?: Record + loading?: 'eager' | 'lazy' + title: string + videoId?: string // Optional for playlists + list?: string // For playlists +} + +const { + class: className = '', + cookie = false, + embedParams = {}, + loading = 'lazy', + title, + videoId, + list +} = Astro.props as Props; + +// Construct the embed URL +let baseUrl = `https://www.youtube${cookie ? '' : '-nocookie'}.com/embed`; +let embedUrl = list + ? `${baseUrl}/videoseries?list=${list}` + : `${baseUrl}/${videoId}?${new URLSearchParams(embedParams).toString()}`; + +// Decide thumbnail behavior for single videos +let srcdoc = videoId && !list + ? ` + + + ${title} + + + + + ` + : null; // No `srcdoc` for playlists +--- + +
+