From 2e3ee95c34f09e0923583943a6a6d920d37078a3 Mon Sep 17 00:00:00 2001 From: khalilcodes Date: Fri, 25 Mar 2022 14:37:11 +0300 Subject: [PATCH] create component for youtube video embed link --- site/components/Link.js | 31 +++++++++++++++++++++++++++++++ site/components/MDX.js | 3 ++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 site/components/Link.js diff --git a/site/components/Link.js b/site/components/Link.js new file mode 100644 index 0000000..b1d97df --- /dev/null +++ b/site/components/Link.js @@ -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 ( +
+ +
+ ); + return

; +}; diff --git a/site/components/MDX.js b/site/components/MDX.js index 405122c..154f87f 100644 --- a/site/components/MDX.js +++ b/site/components/MDX.js @@ -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 }) {