Closed plebeius-eth closed 6 months ago
4e070551c588a5ec1fef2f48d48744cd2d936296
const isYoutubeVideoUrl = (parsedUrl: URL): boolean => {
const youtubeVideoPattern = /\/watch\?v=/;
const youtubeHostPatterns = /^(www\.)?(youtube\.com|youtu\.be|yt\.)$/;
return youtubeVideoPattern.test(parsedUrl.pathname + parsedUrl.search) || youtubeHostPatterns.test(parsedUrl.host);
};
what does this do? there's a reason I use a Set of strings, and not regex, this code is ran tons of time, it's a waste of resources to run regex every single link every single rerender
fixed a3db239a302cc35c516426ce6a1019746a482476
it should probably actually be
if (youtubeHosts.has(parsedUrl.host) || (parsedUrl.host.startsWith('yt.') && parsedUrl.searchParams.has('v'))) {
return <YoutubeEmbed parsedUrl={parsedUrl} />;
}
since getYouTubeVideoId
requires it to have a v
param
also
} else if (url.searchParams.has('v')) {
return url.searchParams.get('v');
} else if (url.host.startsWith('yt.')) {
return url.searchParams.get('v');
}
} else if (url.host.startsWith('yt.')) {
will never hit
1d9327ecca37871d1132cd731a070d5565c1ce25
for example links from invidious instances, they still contain the regular video id and yt prefix