about summary refs log tree commit diff
path: root/src/lib/extractHtmlMeta.ts
diff options
context:
space:
mode:
authorAryan Goharzad <arrygoo@gmail.com>2023-01-20 13:54:30 -0500
committerGitHub <noreply@github.com>2023-01-20 12:54:30 -0600
commit2fce1637b4ae01667da8ceafaa07a6266ab88450 (patch)
tree88b50722379bf004df0219b49e04b770afd2b8b8 /src/lib/extractHtmlMeta.ts
parentd4b9ef3b0a89f1a5a97ff37024fe7f8d90891b86 (diff)
downloadvoidsky-2fce1637b4ae01667da8ceafaa07a6266ab88450.tar.zst
Fixes embed links for twitter and tiktok (#74)
Diffstat (limited to 'src/lib/extractHtmlMeta.ts')
-rw-r--r--src/lib/extractHtmlMeta.ts10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lib/extractHtmlMeta.ts b/src/lib/extractHtmlMeta.ts
index 2517262be..038ca81c6 100644
--- a/src/lib/extractHtmlMeta.ts
+++ b/src/lib/extractHtmlMeta.ts
@@ -1,15 +1,18 @@
+import {extractTwitterMeta} from './extractTwitterMeta'
 import {extractYoutubeMeta} from './extractYoutubeMeta'
 
 interface ExtractHtmlMetaInput {
   html: string
   hostname?: string
+  pathname?: string
 }
 
 export const extractHtmlMeta = ({
   html,
   hostname,
+  pathname,
 }: ExtractHtmlMetaInput): Record<string, string> => {
-  const htmlTitleRegex = /<title>([^<]+)<\/title>/i
+  const htmlTitleRegex = /<title.*>([^<]+)<\/title>/i
 
   let res: Record<string, string> = {}
 
@@ -56,9 +59,12 @@ export const extractHtmlMeta = ({
 
   const isYoutubeUrl =
     hostname?.includes('youtube.') || hostname?.includes('youtu.be')
+  const isTwitterUrl = hostname?.includes('twitter.')
+  // Workaround for some websites not having a title or description in the meta tags in the initial serve
   if (isYoutubeUrl) {
-    // Workaround for Youtube not having a title in the meta tags
     res = {...res, ...extractYoutubeMeta(html)}
+  } else if (isTwitterUrl) {
+    res = {...extractTwitterMeta({pathname})}
   }
 
   return res