[site/mdx][s]: add twitter embed component to parse twitter links in markdown

This commit is contained in:
khalilcodes 2022-05-18 19:03:19 +03:00
parent 48cbd1f0d9
commit 20baae0c68
1 changed files with 22 additions and 23 deletions

View File

@ -1,31 +1,30 @@
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",
];
import TwitterEmbed from "./TwitterEmbed";
import { YOUTUBE_REGEX, TWITTER_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>
);
props.children.props.href
) {
if (YOUTUBE_REGEX.test(props.children.props.href)) {
return (
<div className="relative pt-[56.25%] my-8" {...props}>
<ReactPlayer
className="absolute top-0 left-0"
width="100%"
height="100%"
url={props.children.props.href}
/>
</div>
);
}
if (TWITTER_REGEX.test(props.children.props.href)) {
return <TwitterEmbed url={props.children.props.href} {...props} />;
}
}
return <p {...props} />;
};