UNPKG

nuxt-schema-org

Version:

The quickest and easiest way to build Schema.org graphs for Nuxt.

24 lines (21 loc) 763 B
import { z } from '@nuxt/content'; const SchemaOrgNode = z.record(z.string(), z.any()); const schema = z.object({ schemaOrg: z.union([SchemaOrgNode, z.array(SchemaOrgNode).optional()]).optional() }); const headSchema = z.object({ head: z.object({ meta: z.array(z.record(z.string(), z.any()).optional()), script: z.array(z.record(z.string(), z.any()).optional()) }).optional() }); function asSchemaOrgCollection(collection) { if (collection.type === "page") { collection.schema = collection.schema ? schema.extend(collection.schema.shape) : schema; if (!("head" in collection.schema.shape)) { collection.schema = headSchema.extend(collection.schema.shape); } } return collection; } export { asSchemaOrgCollection, schema };