[dyad] Added keyword counting feature - wrote 2 file(s)
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user