el.xwx.moe/lib/shared/getTitle.ts
daniel31x13 4b1017f45b [WIP]
2023-12-06 16:13:11 -05:00

14 lines
347 B
TypeScript

export default async function getTitle(url: string) {
try {
const response = await fetch(url);
const text = await response.text();
// regular expression to find the <title> tag
let match = text.match(/<title.*>([^<]*)<\/title>/);
if (match) return match[1];
else return "";
} catch (err) {
console.log(err);
}
}