From 20baae0c6805efde8620564995130e6571b8e636 Mon Sep 17 00:00:00 2001 From: khalilcodes Date: Wed, 18 May 2022 19:03:19 +0300 Subject: [PATCH] [site/mdx][s]: add twitter embed component to parse twitter links in markdown --- site/components/Link.js | 45 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/site/components/Link.js b/site/components/Link.js index b1d97df..0cb260e 100644 --- a/site/components/Link.js +++ b/site/components/Link.js @@ -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 ( -
- -
- ); + props.children.props.href + ) { + if (YOUTUBE_REGEX.test(props.children.props.href)) { + return ( +
+ +
+ ); + } + + if (TWITTER_REGEX.test(props.children.props.href)) { + return ; + } + } + return

; };