fix: dont fail to render with invalid URLs

This commit is contained in:
Alejandro Gomez 2023-01-14 12:57:36 +01:00
parent 33e233d4a3
commit fa3793362c
No known key found for this signature in database
GPG Key ID: 4DF39E566658C817

View File

@ -12,6 +12,7 @@ import './Text.css'
import { useMemo } from "react";
function transformHttpLink(a) {
try {
const url = new URL(a);
const youtubeId = YoutubeUrlRegex.test(a) && RegExp.$1;
const tweetId = TweetUrlRegex.test(a) && RegExp.$2;
@ -38,7 +39,7 @@ function transformHttpLink(a) {
}
} else if (tweetId) {
return (
<div className="tweet">
<div className="tweet" key={tweetId}>
<TwitterTweetEmbed tweetId={tweetId} />
</div>
)
@ -50,6 +51,7 @@ function transformHttpLink(a) {
className="w-max"
src={`https://www.youtube.com/embed/${youtubeId}`}
title="YouTube video player"
key={youtubeId}
frameBorder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowFullScreen=""
@ -60,6 +62,8 @@ function transformHttpLink(a) {
} else {
return <a href={a} onClick={(e) => e.stopPropagation()}>{a}</a>
}
} catch (error) {
}
return <a href={a} onClick={(e) => e.stopPropagation()}>{a}</a>
}