Skip to content

Commit b20fda8

Browse files
committed
chore(content): broken types
1 parent 7419974 commit b20fda8

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

build.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ export default defineBuildConfig({
1414
'nitropack',
1515
'consola',
1616
'@nuxt/content',
17+
'zod',
1718
],
1819
})

src/content.ts

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { type DefinedCollection, z } from '@nuxt/content'
1+
import type { Collection } from '@nuxt/content'
2+
import { z } from '@nuxt/content'
3+
import type { TypeOf, ZodRawShape } from 'zod'
24

3-
const sitemap = z.object({
5+
export const schema = z.object({
46
loc: z.string().optional(),
57
lastmod: z.date().optional(),
68
changefreq: z.union([z.literal('always'), z.literal('hourly'), z.literal('daily'), z.literal('weekly'), z.literal('monthly'), z.literal('yearly'), z.literal('never')]).optional(),
@@ -34,19 +36,12 @@ const sitemap = z.object({
3436
})).optional(),
3537
}).optional()
3638

37-
export function asSitemapCollection<T extends DefinedCollection>(collection: T): T {
38-
if (collection.type !== 'page') {
39-
return collection
40-
}
41-
if (!collection.schema) {
42-
collection.schema = z.object({
43-
sitemap,
44-
})
45-
}
46-
else {
47-
collection.schema = collection.schema.extend({
48-
sitemap,
49-
})
39+
export type SitemapSchema = TypeOf<typeof schema>
40+
41+
export function asSitemapCollection<T extends ZodRawShape>(collection: Collection<T>): Collection<T> {
42+
if (collection.type === 'page') {
43+
// @ts-expect-error untyped
44+
collection.schema = collection.schema ? collection.schema.extend(schema) : schema
5045
}
5146
return collection
5247
}

0 commit comments

Comments
 (0)