From f10a8308d9f6bfb907c8a2458cbf78b4cfad88d2 Mon Sep 17 00:00:00 2001 From: Aryan Goharzad Date: Thu, 19 Jan 2023 13:53:11 -0500 Subject: Fixes youtube embed issues (#50) * fixes youtube embed * move extractMetaHtml test to its own file * tests cleanup * Add fallback for youtube meta data * lint * Check for youtube in the url domain * use hostname instead of full url to check for link domain * checks only for domain --- src/lib/strings.ts | 51 --------------------------------------------------- 1 file changed, 51 deletions(-) (limited to 'src/lib/strings.ts') diff --git a/src/lib/strings.ts b/src/lib/strings.ts index 04d8656f7..77fe222e4 100644 --- a/src/lib/strings.ts +++ b/src/lib/strings.ts @@ -265,54 +265,3 @@ export function convertBskyAppUrlIfNeeded(url: string): string { } return url } - -const htmlTitleRegex = /([^<]+)<\/title>/i -export function extractHtmlMeta(html: string): Record<string, string> { - const res: Record<string, string> = {} - - { - const match = htmlTitleRegex.exec(html) - if (match) { - res.title = match[1].trim() - } - } - - { - let metaMatch - let propMatch - const metaRe = /<meta[\s]([^>]+)>/gis - while ((metaMatch = metaRe.exec(html))) { - let propName - let propValue - const propRe = /(name|property|content)="([^"]+)"/gis - while ((propMatch = propRe.exec(metaMatch[1]))) { - if (propMatch[1] === 'content') { - propValue = propMatch[2] - } else { - propName = propMatch[2] - } - } - if (!propName || !propValue) { - continue - } - switch (propName?.trim()) { - case 'title': - case 'og:title': - case 'twitter:title': - res.title = propValue?.trim() - break - case 'description': - case 'og:description': - case 'twitter:description': - res.description = propValue?.trim() - break - case 'og:image': - case 'twitter:image': - res.image = propValue?.trim() - break - } - } - } - - return res -} -- cgit 1.4.1