Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions src/content/tutorials/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
),
});
6 changes: 3 additions & 3 deletions src/layouts/TutorialLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ const { showBanner, englishUrl } = checkTranslationBanner(
<Head
title={entry.data.title}
locale={currentLocale}
description={entry.data.authors.join(", ")}
featuredImageSrc={entry.data.featuredImage.src}
description={entry.data.authors?.join(", ")}
featuredImageSrc={entry.data.featuredImage?.src}
/>

<BaseLayout
Expand All @@ -73,7 +73,7 @@ const { showBanner, englishUrl } = checkTranslationBanner(
className="tutorials"
>
{showBanner && <OutdatedTranslationBanner englishUrl={englishUrl} locale={currentLocale} />}
{entry.data.authors && <section role="group" aria-label="authors">By {entry.data.authors.join(", ")}</section>}
{entry.data.authors && <section role="group" aria-label="authors">By {entry.data.authors?.join(", ")}</section>}
{entry.data.authorsNote && <h7>{entry.data.authorsNote}</h7>}
<div class="rendered-markdown">
<Content
Expand Down