Merge pull request #111 from jedmund/update-youtube-regex

Update regex to support Youtube short URLs (take two)
This commit is contained in:
Justin Edmund 2023-01-02 02:36:37 -08:00 committed by GitHub
commit 67fba83239
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<HTMLInputElement>()
const descriptionInput = React.createRef<HTMLTextAreaElement>()
@ -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 = []