[site/components]: replace youtube embed with lite-youtube component

This commit is contained in:
khalilcodes 2022-06-01 18:29:38 +03:00
parent ed85806958
commit d04ee80ea6
2 changed files with 8 additions and 22 deletions

View File

@ -1,30 +1,15 @@
import ReactPlayer from "react-player";
const videoLinks = [
"youtube.com",
"dailymotion.com",
"vimeo.com",
"soundcloud.com",
"facebook.com/watch",
"twitch.com",
];
import LiteYouTubeEmbed from "react-lite-youtube-embed";
import { YOUTUBE_REGEX } from "../lib/constants";
export const Paragraph = (props) => {
if (
typeof props.children == "object" &&
props.children.props &&
props.children.props.href &&
videoLinks.some((str) => props.children.props.href.includes(str))
)
return (
<div className="relative pt-[56.25%]" {...props}>
<ReactPlayer
className="absolute top-0 left-0"
width="100%"
height="100%"
url={props.children.props.href}
/>
</div>
);
YOUTUBE_REGEX.test(props.children.props.href)
) {
const youtubeId = props.children.props.href.split(/^|=|\//).pop();
return <LiteYouTubeEmbed id={youtubeId} />;
}
return <p {...props} />;
};

View File

@ -5,6 +5,7 @@ import { DefaultSeo } from 'next-seo'
import { ThemeProvider } from 'next-themes'
import '../styles/global.css'
import "react-lite-youtube-embed/dist/LiteYouTubeEmbed.css";
import siteConfig from '../config/siteConfig.js'
import Layout from '../components/Layout'
import * as gtag from '../lib/gtag'