Skip to content

Commit 8264002

Browse files
authored
Merge pull request #1288 from doradocodes/1142-2.0b
Merge PR #1142 to 2.0 branch
2 parents 7d87115 + a75be43 commit 8264002

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

src/content/tutorials/config.ts

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,39 @@ export const categories = [
1919
export 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.featuredImageAlt.trim().length > 0 &&
48+
data.description !== undefined &&
49+
data.description.trim().length > 0
50+
);
51+
},
52+
{
53+
message:
54+
"Tutorials must include authors, featuredImage, featuredImageAlt, and description for production builds",
55+
},
56+
),
3757
});

src/layouts/TutorialLayout.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ const relatedExamples =
5050
<Head
5151
title={entry.data.title}
5252
locale={currentLocale}
53-
description={entry.data.authors.join(", ")}
54-
featuredImageSrc={entry.data.featuredImage.src}
53+
description={entry.data.authors?.join(", ")}
54+
featuredImageSrc={entry.data.featuredImage?.src}
5555
/>
5656

5757
<BaseLayout
@@ -62,7 +62,7 @@ const relatedExamples =
6262
topic="tutorials"
6363
className="tutorials"
6464
>
65-
{entry.data.authors && <h6>By {entry.data.authors.join(", ")}</h6>}
65+
{entry.data.authors && <section role="group" aria-label="authors">By {entry.data.authors?.join(", ")}</section>}
6666
{entry.data.authorsNote && <h7>{entry.data.authorsNote}</h7>}
6767
<div class="rendered-markdown">
6868
<Content

0 commit comments

Comments
 (0)