diff --git a/src/app/actions.ts b/src/app/actions.ts
index ce6c042..152e2a5 100644
--- a/src/app/actions.ts
+++ b/src/app/actions.ts
@@ -7,10 +7,12 @@ interface FaqItem {
answer: string;
}
-interface HeadlineItem {
+export interface HeadlineNode {
tag: string;
text: string;
length: number;
+ level: number;
+ children: HeadlineNode[];
}
export async function extractMetaData(url: string) {
@@ -79,17 +81,35 @@ export async function extractMetaData(url: string) {
}
});
- const headlines: HeadlineItem[] = [];
+ const headlines: HeadlineNode[] = [];
+ const path: HeadlineNode[] = [];
+
$("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,
- });
+ if (!text) return;
+
+ const level = parseInt(tag.replace("h", ""), 10);
+
+ const node: HeadlineNode = {
+ tag,
+ text,
+ length: text.length,
+ level,
+ children: [],
+ };
+
+ while (path.length > 0 && path[path.length - 1].level >= level) {
+ path.pop();
}
+
+ if (path.length === 0) {
+ headlines.push(node);
+ } else {
+ path[path.length - 1].children.push(node);
+ }
+
+ path.push(node);
});
return {
diff --git a/src/components/headline-tree.tsx b/src/components/headline-tree.tsx
new file mode 100644
index 0000000..cd4767c
--- /dev/null
+++ b/src/components/headline-tree.tsx
@@ -0,0 +1,53 @@
+"use client";
+
+import { Badge } from "@/components/ui/badge";
+import type { HeadlineNode } from "@/app/actions";
+
+interface HeadlineTreeProps {
+ headlines: HeadlineNode[];
+}
+
+const HeadlineNodeDisplay = ({
+ node,
+ level,
+}: {
+ node: HeadlineNode;
+ level: number;
+}) => {
+ return (
+
+
+
+ {node.tag}
+
+
{node.text}
+
+ {node.length}
+
+
+ {node.children && node.children.length > 0 && (
+
+ {node.children.map((child, index) => (
+
+ ))}
+
+ )}
+
+ );
+};
+
+export function HeadlineTree({ headlines }: HeadlineTreeProps) {
+ return (
+
+ {headlines.map((headline, index) => (
+
+ ))}
+
+ );
+}
\ No newline at end of file
diff --git a/src/components/headlines-display.tsx b/src/components/headlines-display.tsx
deleted file mode 100644
index 8dff9a7..0000000
--- a/src/components/headlines-display.tsx
+++ /dev/null
@@ -1,48 +0,0 @@
-"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 (
-
-
-
-
- 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 836ccac..8446a8b 100644
--- a/src/components/meta-form.tsx
+++ b/src/components/meta-form.tsx
@@ -6,20 +6,20 @@ import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Globe, Edit, Check, Loader2, X, ImageOff } from "lucide-react";
-import { extractMetaData } from "@/app/actions";
+import { extractMetaData, type HeadlineNode } from "@/app/actions";
import { LengthIndicator } from "./length-indicator";
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";
+import { HeadlineTree } from "./headline-tree";
interface MetaData {
title: string;
description: string;
image?: string | null;
faq?: { question: string; answer: string }[] | null;
- headlines?: { tag: string; text: string; length: number }[] | null;
+ headlines?: HeadlineNode[] | null;
}
export function MetaForm() {
@@ -283,11 +283,11 @@ export function MetaForm() {
- Headlines
+ Headlines Structure
-
+
)}
diff --git a/src/components/results-skeleton.tsx b/src/components/results-skeleton.tsx
index 5067c07..be67f32 100644
--- a/src/components/results-skeleton.tsx
+++ b/src/components/results-skeleton.tsx
@@ -61,13 +61,17 @@ export function ResultsSkeleton() {
-
+