a tool for shared writing and social publishing

add more resilient youtube embed check in BlockifyLink

+8 -6
+8 -6
components/Blocks/TextBlock/index.tsx
··· 458 458 onClick={async (e) => { 459 459 if (!rep.rep) return; 460 460 rep.undoManager.startGroup(); 461 - let isYoutubeUrl = editorState.doc.textContent.startsWith( 462 - "https://www.youtube.com/watch?v=", 463 - ); 464 - if (isYoutubeUrl) { 465 - let url = new URL(editorState.doc.textContent); 466 - let videoId = url.searchParams.get("v"); 461 + function extractYoutubeId(url: string) { 462 + const pattern = 463 + /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/; 464 + const match = url.match(pattern); 465 + return match ? match[1] : null; 466 + } 467 + let videoId = extractYoutubeId(editorState.doc.textContent); 468 + if (videoId) { 467 469 await rep.rep.mutate.assertFact([ 468 470 { 469 471 entity: props.entityID,