Skip to content

Commit

Permalink
Add better parser for twitter and WC
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDaub committed Dec 2, 2024
1 parent 59d39d2 commit 4160bfb
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/parser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ const filtered = [
"kiwinews.xyz",
"kiwinews.io",
"instagram.com",
"warpcast.com",
"twitter.com",
"x.com",
];

async function extractCanonicalLink(html) {
Expand Down Expand Up @@ -74,7 +71,34 @@ const checkOgImage = async (url) => {
}
};

const getYTId = (url) => {
try {
const u = new URL(url);
if (u.hostname === "youtu.be") return u.pathname.slice(1);
if (u.hostname === "youtube.com" || u.hostname === "www.youtube.com") {
return u.searchParams.get("v");
}
return null;
} catch {
return null;
}
};

export const metadata = async (url) => {
let urlObj;
try {
urlObj = new URL(url);
} catch {
throw new Error("Invalid URL");
}

const { hostname } = urlObj;

if (hostname === "twitter.com" || hostname === "x.com") {
urlObj.hostname = "fxtwitter.com";
url = urlObj.toString();
}

let result, html;
if (cache.has(url)) {
const fromCache = cache.get(url);
Expand Down

0 comments on commit 4160bfb

Please sign in to comment.