[dyad] Improved nested schema layout - wrote 1 file(s)

This commit is contained in:
[dyad]
2026-01-20 15:22:09 +01:00
parent aca2cad7c7
commit d087c45216

View File

@@ -145,36 +145,42 @@ const SchemaObjectRenderer = ({
{Object.entries(data).map(([key, value]) => { {Object.entries(data).map(([key, value]) => {
if (key === "@context") return null; if (key === "@context") return null;
// Custom rendering for FAQPage questions let labelDiv: React.ReactNode;
let valueDiv: React.ReactNode;
const isDeepEntry = typeof value === "object" && value !== null;
// Handle FAQPage custom rendering
if ( if (
key === "mainEntity" && key === "mainEntity" &&
data["@type"] === "FAQPage" && data["@type"] === "FAQPage" &&
Array.isArray(value) Array.isArray(value)
) { ) {
return ( labelDiv = (
<React.Fragment key={key}>
<div className="flex items-center gap-2 font-semibold text-sm text-muted-foreground flex-shrink-0 whitespace-nowrap pt-0.5"> <div className="flex items-center gap-2 font-semibold text-sm text-muted-foreground flex-shrink-0 whitespace-nowrap pt-0.5">
<span>Questions</span> <span>Questions</span>
</div> </div>
);
valueDiv = (
<div className="text-sm text-foreground space-y-2"> <div className="text-sm text-foreground space-y-2">
{value.map((item, index) => ( {value.map((item, index) => (
<FaqQuestion key={index} item={item} /> <FaqQuestion key={index} item={item} />
))} ))}
</div> </div>
</React.Fragment>
); );
} } else {
// General rendering
const label = const label =
keyMappings[key] || key.charAt(0).toUpperCase() + key.slice(1); keyMappings[key] || key.charAt(0).toUpperCase() + key.slice(1);
const Icon = keyIcons[key]; const Icon = keyIcons[key];
return ( labelDiv = (
<React.Fragment key={key}>
<div className="flex items-center gap-2 font-semibold text-sm text-muted-foreground flex-shrink-0 whitespace-nowrap"> <div className="flex items-center gap-2 font-semibold text-sm text-muted-foreground flex-shrink-0 whitespace-nowrap">
{Icon && <Icon className="h-4 w-4" />} {Icon && <Icon className="h-4 w-4" />}
<span>{label}</span> <span>{label}</span>
</div> </div>
);
valueDiv = (
<div className="text-sm text-foreground"> <div className="text-sm text-foreground">
{key === "@type" ? ( {key === "@type" ? (
<Badge variant="secondary">{value as string}</Badge> <Badge variant="secondary">{value as string}</Badge>
@@ -182,8 +188,26 @@ const SchemaObjectRenderer = ({
renderValue(value, level) renderValue(value, level)
)} )}
</div> </div>
);
}
if (isDeepEntry) {
return (
<React.Fragment key={key}>
{labelDiv}
{/* This empty div acts as a placeholder in the grid's second column, forcing the value to the next row */}
<div></div>
<div className="md:col-span-2">{valueDiv}</div>
</React.Fragment> </React.Fragment>
); );
} else {
return (
<React.Fragment key={key}>
{labelDiv}
{valueDiv}
</React.Fragment>
);
}
})} })}
</div> </div>
); );