UNPKG

nuxt-schema-org

Version:

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

25 lines (22 loc) 821 B
import { z } from '@nuxt/content'; const SchemaOrgNode = z.record(z.string(), z.any()); const schemaOrgSchema = z.union([SchemaOrgNode, z.array(SchemaOrgNode).optional()]).optional(); const schema = z.object({ schemaOrg: schemaOrgSchema }); 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, schemaOrgSchema };