tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
29
pulls
pipelines
add more resilient youtube embed check in BlockifyLink
schlage.town
6 months ago
9321d0a6
4164cbaa
+8
-6
1 changed file
expand all
collapse all
unified
split
components
Blocks
TextBlock
index.tsx
+8
-6
components/Blocks/TextBlock/index.tsx
···
458
458
onClick={async (e) => {
459
459
if (!rep.rep) return;
460
460
rep.undoManager.startGroup();
461
461
-
let isYoutubeUrl = editorState.doc.textContent.startsWith(
462
462
-
"https://www.youtube.com/watch?v=",
463
463
-
);
464
464
-
if (isYoutubeUrl) {
465
465
-
let url = new URL(editorState.doc.textContent);
466
466
-
let videoId = url.searchParams.get("v");
461
461
+
function extractYoutubeId(url: string) {
462
462
+
const pattern =
463
463
+
/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/;
464
464
+
const match = url.match(pattern);
465
465
+
return match ? match[1] : null;
466
466
+
}
467
467
+
let videoId = extractYoutubeId(editorState.doc.textContent);
468
468
+
if (videoId) {
467
469
await rep.rep.mutate.assertFact([
468
470
{
469
471
entity: props.entityID,