From e958727ab3f58741df033f3d524a21a2e0bcb6ff Mon Sep 17 00:00:00 2001 From: Harsh Date: Thu, 5 Feb 2026 22:11:18 +0530 Subject: [PATCH 1/2] Fix TutorialLayout crash for tutorials without optional fields --- src/content/tutorials/config.ts | 48 ++++++++++++++++++++++---------- src/layouts/TutorialLayout.astro | 4 +-- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/content/tutorials/config.ts b/src/content/tutorials/config.ts index d2b82c673c..e6b681956b 100644 --- a/src/content/tutorials/config.ts +++ b/src/content/tutorials/config.ts @@ -17,19 +17,37 @@ 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.description !== undefined + ); + }, + { + 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..bc32686c1e 100644 --- a/src/layouts/TutorialLayout.astro +++ b/src/layouts/TutorialLayout.astro @@ -60,8 +60,8 @@ const { showBanner, englishUrl } = checkTranslationBanner( Date: Fri, 6 Feb 2026 23:37:40 +0530 Subject: [PATCH 2/2] Address review feedback from ksen0 --- src/content/tutorials/config.ts | 4 +++- src/layouts/TutorialLayout.astro | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/content/tutorials/config.ts b/src/content/tutorials/config.ts index e6b681956b..d3f9d1783f 100644 --- a/src/content/tutorials/config.ts +++ b/src/content/tutorials/config.ts @@ -42,7 +42,9 @@ export const tutorialsCollection = defineCollection({ data.authors.length > 0 && data.featuredImage !== undefined && data.featuredImageAlt !== undefined && - data.description !== undefined + data.featuredImageAlt.trim().length > 0 && + data.description !== undefined && + data.description.trim().length > 0 ); }, { diff --git a/src/layouts/TutorialLayout.astro b/src/layouts/TutorialLayout.astro index bc32686c1e..99cf656f65 100644 --- a/src/layouts/TutorialLayout.astro +++ b/src/layouts/TutorialLayout.astro @@ -73,7 +73,7 @@ const { showBanner, englishUrl } = checkTranslationBanner( className="tutorials" > {showBanner && } - {entry.data.authors &&
By {entry.data.authors.join(", ")}
} + {entry.data.authors &&
By {entry.data.authors?.join(", ")}
} {entry.data.authorsNote && {entry.data.authorsNote}}