From 2fce1637b4ae01667da8ceafaa07a6266ab88450 Mon Sep 17 00:00:00 2001 From: Aryan Goharzad Date: Fri, 20 Jan 2023 13:54:30 -0500 Subject: Fixes embed links for twitter and tiktok (#74) --- src/lib/extractTwitterMeta.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/lib/extractTwitterMeta.ts (limited to 'src/lib/extractTwitterMeta.ts') diff --git a/src/lib/extractTwitterMeta.ts b/src/lib/extractTwitterMeta.ts new file mode 100644 index 000000000..d785903c0 --- /dev/null +++ b/src/lib/extractTwitterMeta.ts @@ -0,0 +1,20 @@ +export const extractTwitterMeta = ({ + pathname, +}: { + pathname: string +}): Record => { + const res = {title: 'Twitter'} + const parsedPathname = pathname.split('/') + if (parsedPathname.length <= 1 || parsedPathname[1].length <= 1) { + // Excluding one letter usernames as they're reserved by twitter for things like cases like twitter.com/i/articles/follows/-1675653703 + return res + } + const username = parsedPathname?.[1] + const isUserProfile = parsedPathname?.length === 2 + + res.title = isUserProfile + ? `@${username} on Twitter` + : `Tweet by @${username}` + + return res +} -- cgit 1.4.1