Add translations for tags and improve feed

This commit is contained in:
Bad Manners 2024-10-09 10:26:03 -03:00
parent ecb8618a67
commit 1dda4c9af8
No known key found for this signature in database
GPG key ID: 8C88292CCB075609
12 changed files with 75 additions and 24 deletions

View file

@ -145,7 +145,7 @@ const copyrightedCharacters = z
`"copyrightedCharacters" cannot mix empty catch-all key with other keys`,
)
.default({});
/** A record of the format `{ en: string, tok?: string, ... }`. */
/** A record with a mandatory `en` value and optional strings for the remaining languages. */
const langRecord = z.object({ [DEFAULT_LANG]: z.string() }).and(z.record(lang, z.string()));
/** Common attributes for published content (stories + games). */
const publishedContent = z
@ -241,7 +241,6 @@ const publishedContent = z
)
.refine(({ isDraft, pubDate }) => isDraft || pubDate, `Missing "pubDate" for published content`)
.refine(({ isDraft, description }) => isDraft || description, `Missing "description" for published content`)
.refine(({ isDraft, pubDate }) => isDraft || pubDate, `Missing "pubDate" for published content`)
.refine(({ isDraft, tags }) => isDraft || tags.length, `Missing "tags" for published content`);
// Types
@ -312,14 +311,16 @@ const blogCollection = defineCollection({
schema: ({ image }) =>
z
.object({
// Optional parameters
// Required parameters, but optional for drafts (isDraft === true)
thumbnail: image().optional(),
// Optional parameters
thumbnailWidth: z.number().int().optional(),
thumbnailHeight: z.number().int().optional(),
prev: reference("blog").nullish(),
next: reference("blog").nullish(),
})
.and(publishedContent),
.and(publishedContent)
.refine(({ isDraft, thumbnail }) => isDraft || thumbnail, `Missing "thumbnail" for published blog post`),
});
// Data collections
@ -364,7 +365,7 @@ const tagCategoriesCollection = defineCollection({
.array(
z.object({
name: langRecord.or(z.string()),
description: z.string().trim().optional(),
description: langRecord.or(z.string().trim()).optional(),
related: z.array(z.string()).default([]),
}),
)