From 1c375385f363899c4b629f76789371c11a3f8d35 Mon Sep 17 00:00:00 2001 From: christinaroise Date: Tue, 10 Sep 2024 22:19:54 +0200 Subject: [PATCH] revert changes to blogpost --- studioShared/schemas/documents/blogPosts.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/studioShared/schemas/documents/blogPosts.ts b/studioShared/schemas/documents/blogPosts.ts index 599c567d0..9b4c52ed4 100644 --- a/studioShared/schemas/documents/blogPosts.ts +++ b/studioShared/schemas/documents/blogPosts.ts @@ -23,8 +23,13 @@ const blogPosts = defineType({ // Ensure date is not undefined or null if (!date) return "The publish date is required."; + // Ensure context.document is defined and _createdAt exists + if (!context.document || !context.document._createdAt) { + return "Creation date is missing."; + } + const selectedDate = new Date(date); - const createdAt = new Date(context.document?._createdAt as string); + const createdAt = new Date(context.document._createdAt as string); const now = new Date(); // Add a small buffer of 1 second (1000 milliseconds) @@ -45,12 +50,6 @@ const blogPosts = defineType({ ...richText, description: "Enter the body content of the post.", }), - defineField({ - name: "language", - type: "string", - readOnly: true, - hidden: true, - }), ], preview: { select: { @@ -59,7 +58,7 @@ const blogPosts = defineType({ }, prepare({ title, date }) { const subtitles = [date && format(parseISO(date), "LLL d, yyyy")].filter( - Boolean, + Boolean ); return { title, subtitle: subtitles.join(" ") };