2023-06-09 17:31:14 -05:00
|
|
|
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-03-08 15:31:24 -06:00
|
|
|
|
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);
|
|
|
|
}
|
2023-06-09 17:31:14 -05:00
|
|
|
}
|