@@ -19,19 +19,37 @@ export const categories = [
1919export const tutorialsCollection = defineCollection ( {
2020 type : "content" ,
2121 schema : ( { image } ) =>
22- z . object ( {
23- // Title of the tutorial
24- title : z . string ( ) ,
25- // People who wrote the tutorial
26- authors : z . array ( z . string ( ) ) . optional ( ) ,
27- // Optional note explaining more context about the authors
28- authorsNote : z . string ( ) . optional ( ) ,
29- description : z . string ( ) . optional ( ) ,
30- category : z . enum ( categories ) ,
31- categoryIndex : z . number ( ) . optional ( ) ,
32- // Image to use as a thumbnail for the tutorial
33- featuredImage : image ( ) . optional ( ) ,
34- featuredImageAlt : z . string ( ) . optional ( ) ,
35- relatedContent : relatedContent ( ) . optional ( ) ,
36- } ) ,
22+ z
23+ . object ( {
24+ // Title of the tutorial
25+ title : z . string ( ) ,
26+ // People who wrote the tutorial
27+ authors : z . array ( z . string ( ) ) . optional ( ) ,
28+ // Optional note explaining more context about the authors
29+ authorsNote : z . string ( ) . optional ( ) ,
30+ description : z . string ( ) . optional ( ) ,
31+ category : z . enum ( categories ) ,
32+ categoryIndex : z . number ( ) . optional ( ) ,
33+ // Image to use as a thumbnail for the tutorial
34+ featuredImage : image ( ) . optional ( ) ,
35+ featuredImageAlt : z . string ( ) . optional ( ) ,
36+ relatedContent : relatedContent ( ) . optional ( ) ,
37+ } )
38+ . refine (
39+ ( data ) => {
40+ // Allow missing fields during development for quicker iteration
41+ if ( import . meta. env . DEV ) return true ;
42+ return (
43+ data . authors !== undefined &&
44+ data . authors . length > 0 &&
45+ data . featuredImage !== undefined &&
46+ data . featuredImageAlt !== undefined &&
47+ data . description !== undefined
48+ ) ;
49+ } ,
50+ {
51+ message :
52+ "Tutorials must include authors, featuredImage, featuredImageAlt, and description for production builds" ,
53+ } ,
54+ ) ,
3755} ) ;
0 commit comments