UNPKG

nuxt-schema-org

Version:

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

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