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