[dyad] Added image alt tag analysis - wrote 3 file(s)

This commit is contained in:
[dyad]
2026-01-20 14:22:07 +01:00
parent 3aac69a4a3
commit e889bb3570
3 changed files with 115 additions and 1 deletions

View File

@@ -15,6 +15,11 @@ export interface HeadlineNode {
children: HeadlineNode[];
}
export interface ImageAltData {
src: string;
alt: string;
}
export async function extractMetaData(url: string, keyword?: string) {
if (!url) {
return { error: "URL is required." };
@@ -122,6 +127,24 @@ export async function extractMetaData(url: string, keyword?: string) {
keywordCount = matches ? matches.length : 0;
}
const imageAltData: ImageAltData[] = [];
$("img").each((i, el) => {
const src = $(el).attr("src");
const alt = $(el).attr("alt") || "";
if (src) {
try {
const absoluteSrc = new URL(src, formattedUrl).href;
imageAltData.push({
src: absoluteSrc,
alt: alt.trim(),
});
} catch (e) {
// Ignore invalid URLs
}
}
});
return {
data: {
title,
@@ -131,6 +154,7 @@ export async function extractMetaData(url: string, keyword?: string) {
headlines: headlines.length > 0 ? headlines : null,
keyword: trimmedKeyword || null,
keywordCount,
images: imageAltData.length > 0 ? imageAltData : null,
},
};
} catch (error) {