From ff5e9ce5c0aecc7fdb743f82b50bb10c507851fa Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Mon, 2 Jan 2023 02:35:39 -0800 Subject: [PATCH] Update regex to support Youtube short URLs Mya just had to go and fucking use the short URLs and break embedding --- components/PartyDetails/index.tsx | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/components/PartyDetails/index.tsx b/components/PartyDetails/index.tsx index 36eef570..2fd0e153 100644 --- a/components/PartyDetails/index.tsx +++ b/components/PartyDetails/index.tsx @@ -46,6 +46,9 @@ const PartyDetails = (props: Props) => { const router = useRouter() const locale = router.locale || 'en' + const youtubeUrlRegex = + /(?:https:\/\/www\.youtube\.com\/watch\?v=|https:\/\/youtu\.be\/)([\w-]+)/g + const nameInput = React.createRef() const descriptionInput = React.createRef() @@ -113,9 +116,6 @@ const PartyDetails = (props: Props) => { // Wait for all the video titles to be fetched Promise.all(fetchPromises).then((videoTitles) => { - // YouTube regex - const youtubeUrlRegex = - /https:\/\/www\.youtube\.com\/watch\?v=([\w-]+)/g // Replace the video URLs in the description with LiteYoutubeEmbed elements const newDescription = reactStringReplace( appState.party.description, @@ -163,10 +163,6 @@ const PartyDetails = (props: Props) => { } function extractYoutubeVideoIds(text: string) { - // Create a regular expression to match Youtube URLs in the text - const youtubeUrlRegex = - /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/watch\?v=)([^&]+)/ - // Initialize an array to store the video IDs const videoIds = []