[dyad] Added headline extraction and display - wrote 4 file(s)
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user