create component for youtube video embed link

This commit is contained in:
khalilcodes 2022-03-25 14:37:11 +03:00
parent 72beb533c5
commit 2e3ee95c34
2 changed files with 33 additions and 1 deletions

31
site/components/Link.js Normal file
View File

@ -0,0 +1,31 @@
import Link from "next/link";
import ReactPlayer from "react-player";
const videoLinks = [
"youtube.com",
"dailymotion.com",
"vimeo.com",
"soundcloud.com",
"facebook.com/watch",
"twitch.com",
];
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>
);
return <p {...props} />;
};

View File

@ -1,8 +1,9 @@
import Head from 'next/head'
import Link from 'next/link'
import { Paragraph } from './Link'
const components = {
Head,
p: Paragraph
}
export default function MdxPage({ children }) {