Skip to content

Commit 0fa0c6d

Browse files
committed
fix: post schema config
1 parent de6802c commit 0fa0c6d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

source.config.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,20 @@ export const blog = defineCollections({
1414
type: 'doc',
1515
dir: 'content',
1616
schema: frontmatterSchema.extend({
17-
date: z.string().date().or(z.date()),
17+
date: z
18+
.string()
19+
.or(z.date())
20+
.transform((value, context) => {
21+
try {
22+
return new Date(value);
23+
} catch {
24+
context.addIssue({
25+
code: z.ZodIssueCode.custom,
26+
message: 'Invalid date',
27+
});
28+
return z.NEVER;
29+
}
30+
}),
1831
tags: z.array(z.string()).optional(),
1932
}),
2033
});

0 commit comments

Comments
 (0)