[dyad] Added headline extraction and display - wrote 4 file(s)

This commit is contained in:
[dyad]
2026-01-20 13:56:24 +01:00
parent cbd7f55d92
commit dd690eba2e
4 changed files with 86 additions and 1 deletions

View File

@@ -7,6 +7,12 @@ interface FaqItem {
answer: string;
}
interface HeadlineItem {
tag: string;
text: string;
length: number;
}
export async function extractMetaData(url: string) {
if (!url) {
return { error: "URL is required." };
@@ -73,12 +79,26 @@ export async function extractMetaData(url: string) {
}
});
const headlines: HeadlineItem[] = [];
$("h1, h2, h3, h4, h5, h6").each((i, el) => {
const tag = $(el).prop("tagName").toLowerCase();
const text = $(el).text().trim();
if (text) {
headlines.push({
tag,
text,
length: text.length,
});
}
});
return {
data: {
title,
description,
image,
faq: faqData.length > 0 ? faqData : null,
headlines: headlines.length > 0 ? headlines : null,
},
};
} catch (error) {