From 03041ec5030cb804703c53ff76f71a5d81ab9abf Mon Sep 17 00:00:00 2001 From: khalilcodes Date: Mon, 20 Jun 2022 21:31:51 +0300 Subject: [PATCH] [site/components][s]: add start time support for youtube embeds --- site/components/Paragraph.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/site/components/Paragraph.js b/site/components/Paragraph.js index c3e985d..746af8c 100644 --- a/site/components/Paragraph.js +++ b/site/components/Paragraph.js @@ -1,6 +1,6 @@ import LiteYouTubeEmbed from "react-lite-youtube-embed"; import TwitterEmbed from "./TwitterEmbed"; -import { YOUTUBE_REGEX, TWITTER_REGEX } from "../lib/constants"; +import { YOUTUBE_REGEX, TWITTER_REGEX, YOUTUBE_ID_REGEX } from "../lib/constants"; export const Paragraph = (props) => { if ( @@ -8,13 +8,17 @@ export const Paragraph = (props) => { props.children.props && props.children.props.href ) { - if (YOUTUBE_REGEX.test(props.children.props.href)) { - const youtubeId = props.children.props.href.split(/^|=|\//).pop(); - return ; + const href = props.children.props.href + + if (YOUTUBE_REGEX.test(href)) { + const youtubeId = href.match(YOUTUBE_ID_REGEX)[1]; + let startTime = href.match(/t=[0-9]*/) + if (startTime) startTime = startTime[0].split("=").pop() + return ; } - if (TWITTER_REGEX.test(props.children.props.href)) { - return ; + if (TWITTER_REGEX.test(href)) { + return ; } } return

;