Files

17 lines
499 B
TypeScript
Raw Permalink Normal View History

import { toJsonLd } from "#shared/seo/schema";
type Ld = Record<string, unknown>;
/** Renders JSON-LD <script> tags at the start of <body> (replaces the React <JsonLd> component). */
export function useJsonLd(data: Ld | Ld[], id = "site") {
const items = Array.isArray(data) ? data : [data];
useHead({
script: items.map((item, i) => ({
key: `ld-${id}-${i}`,
type: "application/ld+json",
innerHTML: toJsonLd(item),
tagPosition: "bodyOpen" as const,
})),
});
}