From f901165a29fa5cdd3bad23e54ed29d57932339b4 Mon Sep 17 00:00:00 2001 From: "[dyad]" Date: Tue, 20 Jan 2026 14:50:38 +0100 Subject: [PATCH] [dyad] Improved schema display - wrote 2 file(s) --- src/components/pretty-schema-display.tsx | 146 +++++++++++++++++++++++ src/components/schema-display.tsx | 57 +++++---- 2 files changed, 183 insertions(+), 20 deletions(-) create mode 100644 src/components/pretty-schema-display.tsx diff --git a/src/components/pretty-schema-display.tsx b/src/components/pretty-schema-display.tsx new file mode 100644 index 0000000..e2bc945 --- /dev/null +++ b/src/components/pretty-schema-display.tsx @@ -0,0 +1,146 @@ +"use client"; + +import React from "react"; +import { Badge } from "@/components/ui/badge"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { + Link as LinkIcon, + Type, + Image as ImageIcon, + User, + Building, + Calendar, + HelpCircle, + Hash, + Text, +} from "lucide-react"; + +const keyMappings: { [key: string]: string } = { + "@type": "Type", + "@context": "Context", + "@id": "ID", + name: "Name", + headline: "Headline", + description: "Description", + author: "Author", + publisher: "Publisher", + mainEntityOfPage: "Main Page", + image: "Image", + datePublished: "Date Published", + dateModified: "Date Modified", + acceptedAnswer: "Answer", + mainEntity: "Main Content", + url: "URL", + text: "Text", + question: "Question", + answer: "Answer", + logo: "Logo", + telephone: "Telephone", + email: "Email", +}; + +const keyIcons: { [key: string]: React.ElementType } = { + "@type": Type, + "@id": Hash, + url: LinkIcon, + image: ImageIcon, + logo: ImageIcon, + author: User, + publisher: Building, + datePublished: Calendar, + dateModified: Calendar, + question: HelpCircle, + text: Text, +}; + +const renderValue = (value: any): React.ReactNode => { + if (typeof value === "string") { + if (value.startsWith("http://") || value.startsWith("https://")) { + try { + const url = new URL(value); + return ( + + + + {url.hostname} + {url.pathname.length > 1 ? "/..." : ""} + + + ); + } catch (e) { + return {value}; + } + } + return {value}; + } + + if (typeof value === "object" && value !== null) { + if (Array.isArray(value)) { + return ( +
+ {value.map((item, index) => ( +
{renderValue(item)}
+ ))} +
+ ); + } + return ; + } + + return {String(value)}; +}; + +const SchemaObjectRenderer = ({ + data, + isNested = false, +}: { + data: any; + isNested?: boolean; +}) => { + const content = ( +
+ {Object.entries(data).map(([key, value]) => { + if (key === "@context") return null; + const label = + keyMappings[key] || key.charAt(0).toUpperCase() + key.slice(1); + const Icon = keyIcons[key]; + + return ( +
+
+ {Icon && } + {label}: +
+
+ {key === "@type" ? ( + {value as string} + ) : ( + renderValue(value) + )} +
+
+ ); + })} +
+ ); + + if (isNested) { + return ( +
{content}
+ ); + } + + return content; +}; + +export function PrettySchemaDisplay({ schema }: { schema: any }) { + return ; +} \ No newline at end of file diff --git a/src/components/schema-display.tsx b/src/components/schema-display.tsx index 1d3e205..9407da6 100644 --- a/src/components/schema-display.tsx +++ b/src/components/schema-display.tsx @@ -7,6 +7,7 @@ import { AccordionTrigger, } from "@/components/ui/accordion"; import { CopyButton } from "./copy-button"; +import { PrettySchemaDisplay } from "./pretty-schema-display"; interface SchemaDisplayProps { schemas: any[]; @@ -14,27 +15,43 @@ interface SchemaDisplayProps { export function SchemaDisplay({ schemas }: SchemaDisplayProps) { return ( - - {schemas.map((schema, index) => { - const schemaType = schema["@type"] || `Schema Block ${index + 1}`; - const schemaJson = JSON.stringify(schema, null, 2); +
+
+

+ Found {schemas.length} schema block{schemas.length > 1 ? "s" : ""} on + this page. +

+

Expand to see details.

+
+ + {schemas.map((schema, index) => { + const schemaType = schema["@type"] || `Schema Block ${index + 1}`; + const schemaJson = JSON.stringify(schema, null, 2); - return ( - - {schemaType} - -
-
- + return ( + + +
+ {schemaType} +
+ + Copy Raw JSON + + +
-
-                  {schemaJson}
-                
-
- - - ); - })} - + + + + + + ); + })} + +
); } \ No newline at end of file