From 52f57f8ac5f2ce550629e1c94b2fbc8d18a23095 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 28 May 2024 14:18:32 +0100 Subject: [PATCH] Embed Rumble Video (#1191) * Render Rumble video in preview and posts * Display Rumble video * Remove workspace * Add util function * Use searchParam for id * Update check for Rumble * Update youtube match strings * fix hostname conditions --------- Co-authored-by: keyan --- components/item-full.js | 28 +++++++++++++++++++++------ components/text.js | 36 ++++++++++++++++++++++++++++------- components/text.module.css | 4 ++-- lib/url.js | 39 ++++++++++++++++++++++++++++++++++++++ middleware.js | 2 +- styles/item.module.css | 16 ++++++++-------- 6 files changed, 101 insertions(+), 24 deletions(-) diff --git a/components/item-full.js b/components/item-full.js index 0b440c94..222fce63 100644 --- a/components/item-full.js +++ b/components/item-full.js @@ -22,7 +22,7 @@ import Share from './share' import Toc from './table-of-contents' import Link from 'next/link' import { RootProvider } from './root' -import { IMGPROXY_URL_REGEXP } from '@/lib/url' +import { IMGPROXY_URL_REGEXP, parseEmbedUrl } from '@/lib/url' import { numWithUnits } from '@/lib/format' import { useQuoteReply } from './use-quote-reply' import { UNKNOWN_LINK_REL } from '@/lib/constants' @@ -70,6 +70,7 @@ function ItemEmbed ({ item }) { const [overflowing, setOverflowing] = useState(false) const [show, setShow] = useState(false) + // This Twitter embed could use similar logic to the video embeds below const twitter = item.url?.match(/^https?:\/\/(?:twitter|x)\.com\/(?:#!\/)?\w+\/status(?:es)?\/(?\d+)/) if (twitter?.groups?.id) { return ( @@ -83,14 +84,15 @@ function ItemEmbed ({ item }) { ) } - const youtube = item.url?.match(/(https?:\/\/)?((www\.)?(youtube(-nocookie)?|youtube.googleapis)\.com.*(v\/|v=|vi=|vi\/|e\/|embed\/|user\/.*\/u\/\d+\/)|youtu\.be\/)(?[_0-9a-z-]+)((?:\?|&)(?:t|start)=(?\d+))?/i) - if (youtube?.groups?.id) { + const { provider, id, meta } = parseEmbedUrl(item.url) + + if (provider === 'youtube') { return ( -
+
@@ -98,6 +100,20 @@ function ItemEmbed ({ item }) { ) } + if (provider === 'rumble') { + return ( +
+
+