el.xwx.moe/lib/shared/getTitle.ts

14 lines
347 B
TypeScript
Raw Normal View History

export default async function getTitle(url: string) {
2023-06-26 18:35:12 -05:00
try {
const response = await fetch(url);
const text = await response.text();
2023-06-26 18:35:12 -05:00
// regular expression to find the <title> tag
let match = text.match(/<title.*>([^<]*)<\/title>/);
2023-07-24 08:39:51 -05:00
if (match) return match[1];
2023-06-26 18:35:12 -05:00
else return "";
} catch (err) {
console.log(err);
}
}