diff --git a/src/content/tutorials/config.ts b/src/content/tutorials/config.ts index d2b82c673c..d3f9d1783f 100644 --- a/src/content/tutorials/config.ts +++ b/src/content/tutorials/config.ts @@ -17,19 +17,39 @@ export const categories = [ export const tutorialsCollection = defineCollection({ type: "content", schema: ({ image }) => - z.object({ - // Title of the tutorial - title: z.string(), - // People who wrote the tutorial - authors: z.array(z.string()).optional(), - // Optional note explaining more context about the authors - authorsNote: z.string().optional(), - description: z.string().optional(), - category: z.enum(categories), - categoryIndex: z.number().optional(), - // Image to use as a thumbnail for the tutorial - featuredImage: image().optional(), - featuredImageAlt: z.string().optional(), - relatedContent: relatedContent().optional(), - }), + z + .object({ + // Title of the tutorial + title: z.string(), + // People who wrote the tutorial + authors: z.array(z.string()).optional(), + // Optional note explaining more context about the authors + authorsNote: z.string().optional(), + description: z.string().optional(), + category: z.enum(categories), + categoryIndex: z.number().optional(), + // Image to use as a thumbnail for the tutorial + featuredImage: image().optional(), + featuredImageAlt: z.string().optional(), + relatedContent: relatedContent().optional(), + }) + .refine( + (data) => { + // Allow missing fields during development for quicker iteration + if (import.meta.env.DEV) return true; + return ( + data.authors !== undefined && + data.authors.length > 0 && + data.featuredImage !== undefined && + data.featuredImageAlt !== undefined && + data.featuredImageAlt.trim().length > 0 && + data.description !== undefined && + data.description.trim().length > 0 + ); + }, + { + message: + "Tutorials must include authors, featuredImage, featuredImageAlt, and description for production builds", + }, + ), }); diff --git a/src/layouts/TutorialLayout.astro b/src/layouts/TutorialLayout.astro index 0e9f5bdffe..99cf656f65 100644 --- a/src/layouts/TutorialLayout.astro +++ b/src/layouts/TutorialLayout.astro @@ -60,8 +60,8 @@ const { showBanner, englishUrl } = checkTranslationBanner( {showBanner && } - {entry.data.authors &&
By {entry.data.authors.join(", ")}
} + {entry.data.authors &&
By {entry.data.authors?.join(", ")}
} {entry.data.authorsNote && {entry.data.authorsNote}}