We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e86009f commit 1458a05Copy full SHA for 1458a05
lib/utils.ts
@@ -102,4 +102,21 @@ export function formatDateString(
102
// day: 'numeric',
103
year: 'numeric',
104
});
105
-}
+}
106
+
107
108
+export async function getWebsiteTitle(url: string): Promise<string | null> {
109
+ try {
110
+ const response = await fetch(url);
111
+ const html = await response.text();
112
113
+ const parser = new DOMParser();
114
+ const doc = parser.parseFromString(html, 'text/html');
115
116
+ const title = doc.querySelector('title');
117
+ return title?.innerText || null;
118
+ } catch (error) {
119
+ console.error('Failed to fetch website title:', error);
120
+ return null;
121
+ }
122
0 commit comments