From dd690eba2e6d79ec63d0a00f1ccd9575a63c260c Mon Sep 17 00:00:00 2001 From: "[dyad]" Date: Tue, 20 Jan 2026 13:56:24 +0100 Subject: [PATCH] [dyad] Added headline extraction and display - wrote 4 file(s) --- src/app/actions.ts | 20 +++++++++++ src/components/headlines-display.tsx | 51 ++++++++++++++++++++++++++++ src/components/meta-form.tsx | 7 +++- src/components/results-skeleton.tsx | 9 +++++ 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/components/headlines-display.tsx diff --git a/src/app/actions.ts b/src/app/actions.ts index 6c5e2ae..ce6c042 100644 --- a/src/app/actions.ts +++ b/src/app/actions.ts @@ -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) { diff --git a/src/components/headlines-display.tsx b/src/components/headlines-display.tsx new file mode 100644 index 0000000..970bff8 --- /dev/null +++ b/src/components/headlines-display.tsx @@ -0,0 +1,51 @@ +"use client"; + +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table"; +import { Badge } from "@/components/ui/badge"; + +interface HeadlinesDisplayProps { + headlines: { + tag: string; + text: string; + length: number; + }[]; +} + +export function HeadlinesDisplay({ headlines }: HeadlinesDisplayProps) { + return ( +
+

Headlines

+
+ + + + Tag + Text + Length + + + + {headlines.map((headline, index) => ( + + + + {headline.tag} + + + {headline.text} + {headline.length} + + ))} + +
+
+
+ ); +} \ No newline at end of file diff --git a/src/components/meta-form.tsx b/src/components/meta-form.tsx index f7df065..da895bd 100644 --- a/src/components/meta-form.tsx +++ b/src/components/meta-form.tsx @@ -12,12 +12,14 @@ import { CopyButton } from "./copy-button"; import { SerpPreview } from "./serp-preview"; import { ResultsSkeleton } from "./results-skeleton"; import { FaqDisplay } from "./faq-display"; +import { HeadlinesDisplay } from "./headlines-display"; interface MetaData { title: string; description: string; image?: string | null; faq?: { question: string; answer: string }[] | null; + headlines?: { tag: string; text: string; length: number }[] | null; } export function MetaForm() { @@ -161,7 +163,7 @@ export function MetaForm() { )} - + {metaData.faq && metaData.faq.length > 0 && ( )} @@ -271,6 +273,9 @@ export function MetaForm() {

)} + {metaData.headlines && metaData.headlines.length > 0 && ( + + )} diff --git a/src/components/results-skeleton.tsx b/src/components/results-skeleton.tsx index ef04a8d..e129875 100644 --- a/src/components/results-skeleton.tsx +++ b/src/components/results-skeleton.tsx @@ -63,6 +63,15 @@ export function ResultsSkeleton() { +
+ +
+ + + + +
+