UNPKG

nuxt-schema-org

Version:

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

29 lines (25 loc) 957 B
'use strict'; const zod = require('zod'); const SchemaOrgNode = zod.z.record(zod.z.string(), zod.z.any()); const schemaOrgSchema = zod.z.union([SchemaOrgNode, zod.z.array(SchemaOrgNode).optional()]).optional(); const schema = zod.z.object({ schemaOrg: schemaOrgSchema }); const headSchema = zod.z.object({ head: zod.z.object({ meta: zod.z.array(zod.z.record(zod.z.string(), zod.z.any()).optional()), script: zod.z.array(zod.z.record(zod.z.string(), zod.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; } exports.asSchemaOrgCollection = asSchemaOrgCollection; exports.schema = schema; exports.schemaOrgSchema = schemaOrgSchema;