[site/mdx][s]: add twitter embed component to parse twitter links in markdown
This commit is contained in:
parent
48cbd1f0d9
commit
20baae0c68
|
|
@ -1,31 +1,30 @@
|
||||||
import Link from "next/link";
|
|
||||||
import ReactPlayer from "react-player";
|
import ReactPlayer from "react-player";
|
||||||
|
import TwitterEmbed from "./TwitterEmbed";
|
||||||
const videoLinks = [
|
import { YOUTUBE_REGEX, TWITTER_REGEX } from "../lib/constants";
|
||||||
"youtube.com",
|
|
||||||
"dailymotion.com",
|
|
||||||
"vimeo.com",
|
|
||||||
"soundcloud.com",
|
|
||||||
"facebook.com/watch",
|
|
||||||
"twitch.com",
|
|
||||||
];
|
|
||||||
|
|
||||||
export const Paragraph = (props) => {
|
export const Paragraph = (props) => {
|
||||||
if (
|
if (
|
||||||
typeof props.children == "object" &&
|
typeof props.children == "object" &&
|
||||||
props.children.props &&
|
props.children.props &&
|
||||||
props.children.props.href &&
|
props.children.props.href
|
||||||
videoLinks.some((str) => props.children.props.href.includes(str))
|
) {
|
||||||
)
|
if (YOUTUBE_REGEX.test(props.children.props.href)) {
|
||||||
return (
|
return (
|
||||||
<div className="relative pt-[56.25%]" {...props}>
|
<div className="relative pt-[56.25%] my-8" {...props}>
|
||||||
<ReactPlayer
|
<ReactPlayer
|
||||||
className="absolute top-0 left-0"
|
className="absolute top-0 left-0"
|
||||||
width="100%"
|
width="100%"
|
||||||
height="100%"
|
height="100%"
|
||||||
url={props.children.props.href}
|
url={props.children.props.href}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TWITTER_REGEX.test(props.children.props.href)) {
|
||||||
|
return <TwitterEmbed url={props.children.props.href} {...props} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return <p {...props} />;
|
return <p {...props} />;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue