@@ -2,20 +2,26 @@ import type { Collection } from '@nuxt/content'
22import type { TypeOf , ZodRawShape } from 'zod'
33import { z } from '@nuxt/content'
44
5+ export const ogImageSchema = z . object ( {
6+ url : z . string ( ) . optional ( ) ,
7+ component : z . string ( ) . optional ( ) ,
8+ props : z . record ( z . string ( ) , z . any ( ) ) ,
9+ } ) . optional ( )
10+
511export const schema = z . object ( {
6- ogImage : z . object ( {
7- url : z . string ( ) . optional ( ) ,
8- component : z . string ( ) . optional ( ) ,
9- props : z . record ( z . string ( ) , z . any ( ) ) ,
10- } ) . optional ( ) ,
12+ ogImage : ogImageSchema ,
1113} )
1214
1315export type OgImageSchema = TypeOf < typeof schema >
1416
15- export function asOgImageCollection < T extends ZodRawShape > ( collection : Collection < T > ) : Collection < T > {
17+ type ExtendedSchema < T extends ZodRawShape > = T & {
18+ ogImage : typeof ogImageSchema
19+ }
20+
21+ export function asOgImageCollection < T extends ZodRawShape > ( collection : Collection < T > ) : Collection < ExtendedSchema < T > > {
1622 if ( collection . type === 'page' ) {
1723 // @ts -expect-error untyped
1824 collection . schema = collection . schema ? schema . extend ( collection . schema . shape ) : schema
1925 }
20- return collection
26+ return collection as Collection < ExtendedSchema < T > >
2127}
0 commit comments