[site/mdx][s]: add logic for twitter embeds
This commit is contained in:
parent
007742af23
commit
77e41e922b
|
|
@ -1,15 +1,21 @@
|
||||||
import LiteYouTubeEmbed from "react-lite-youtube-embed";
|
import LiteYouTubeEmbed from "react-lite-youtube-embed";
|
||||||
import { YOUTUBE_REGEX } from "../lib/constants";
|
import TwitterEmbed from "./TwitterEmbed";
|
||||||
|
import { YOUTUBE_REGEX, TWITTER_REGEX } from "../lib/constants";
|
||||||
|
|
||||||
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
|
||||||
YOUTUBE_REGEX.test(props.children.props.href)
|
|
||||||
) {
|
) {
|
||||||
const youtubeId = props.children.props.href.split(/^|=|\//).pop();
|
if (YOUTUBE_REGEX.test(props.children.props.href)) {
|
||||||
return <LiteYouTubeEmbed id={youtubeId} />;
|
const youtubeId = props.children.props.href.split(/^|=|\//).pop();
|
||||||
|
return <LiteYouTubeEmbed id={youtubeId} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
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