mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat(embed): add support to youtube playlists
This commit is contained in:
@@ -49,23 +49,34 @@ interface EmbedComponentProps {
|
||||
const youtubeHosts = new Set<string>(['youtube.com', 'www.youtube.com', 'youtu.be', 'www.youtu.be', 'm.youtube.com', 'music.youtube.com']);
|
||||
|
||||
const YoutubeEmbed = ({ parsedUrl }: EmbedComponentProps) => {
|
||||
let youtubeId = parsedUrl.searchParams.get('v');
|
||||
let embedSrc = '';
|
||||
|
||||
if (!youtubeId && parsedUrl.host.includes('youtu.be')) {
|
||||
youtubeId = parsedUrl.pathname.substring(1);
|
||||
if (parsedUrl.searchParams.has('list')) {
|
||||
const playlistId = parsedUrl.searchParams.get('list');
|
||||
embedSrc = `https://www.youtube.com/embed/videoseries?list=${playlistId}`;
|
||||
} else {
|
||||
let videoId = parsedUrl.searchParams.get('v');
|
||||
|
||||
if (!videoId && parsedUrl.host.includes('youtu.be')) {
|
||||
videoId = parsedUrl.pathname.substring(1);
|
||||
}
|
||||
|
||||
if (videoId) {
|
||||
embedSrc = `https://www.youtube.com/embed/${videoId}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (youtubeId) {
|
||||
if (embedSrc) {
|
||||
return (
|
||||
<iframe
|
||||
className={styles.videoEmbed}
|
||||
height='100%'
|
||||
width='100%'
|
||||
referrerPolicy='origin'
|
||||
allow='accelerometer; encrypted-media; gyroscope; picture-in-picture; web-share'
|
||||
allow='accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share'
|
||||
allowFullScreen
|
||||
title={parsedUrl.href}
|
||||
src={`https://www.youtube.com/embed/${youtubeId}`}
|
||||
src={embedSrc}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user