[dyad] Added keyword counting feature - wrote 2 file(s)

This commit is contained in:
[dyad]
2026-01-20 14:19:08 +01:00
parent 393cb4cf7a
commit 0932ac6447
2 changed files with 57 additions and 3 deletions

View File

@@ -15,7 +15,7 @@ export interface HeadlineNode {
children: HeadlineNode[];
}
export async function extractMetaData(url: string) {
export async function extractMetaData(url: string, keyword?: string) {
if (!url) {
return { error: "URL is required." };
}
@@ -112,6 +112,15 @@ export async function extractMetaData(url: string) {
path.push(node);
});
let keywordCount: number | null = null;
const trimmedKeyword = keyword?.trim();
if (trimmedKeyword) {
const bodyText = $("body").text();
const regex = new RegExp(trimmedKeyword, "gi");
const matches = bodyText.match(regex);
keywordCount = matches ? matches.length : 0;
}
return {
data: {
title,
@@ -119,6 +128,8 @@ export async function extractMetaData(url: string) {
image,
faq: faqData.length > 0 ? faqData : null,
headlines: headlines.length > 0 ? headlines : null,
keyword: trimmedKeyword || null,
keywordCount,
},
};
} catch (error) {