mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-03 06:00:09 +00:00
40 lines
960 B
TypeScript
40 lines
960 B
TypeScript
"use server";
|
|
import * as cheerio from "cheerio";
|
|
|
|
// TODO: THIS SHOULD PROBABLY ALSO FETCH THE OG-IMAGE
|
|
export async function getMetaData(url: string) {
|
|
const response = await fetch(url);
|
|
const html = await response.text();
|
|
|
|
const $ = cheerio.load(html);
|
|
|
|
// Extract the base URL
|
|
const baseUrl = url
|
|
|
|
// Extract title
|
|
const title = $("title").text().trim();
|
|
|
|
const description = $("meta[name=description]").attr("content") ?? "";
|
|
|
|
const _favicon =
|
|
$("link[rel=icon]").attr("href") ?? "https://supermemory.dhr.wtf/web.svg";
|
|
|
|
let favicon =
|
|
_favicon.trim().length > 0
|
|
? _favicon.trim()
|
|
: "https://supermemory.dhr.wtf/web.svg";
|
|
if (favicon.startsWith("/")) {
|
|
favicon = baseUrl + favicon;
|
|
} else if (favicon.startsWith("./")) {
|
|
favicon = baseUrl + favicon.slice(1);
|
|
}
|
|
|
|
// Prepare the metadata object
|
|
const metadata = {
|
|
title,
|
|
description,
|
|
image: favicon,
|
|
baseUrl,
|
|
};
|
|
return metadata;
|
|
}
|