videoMetaSchema

A Zod schema that describes the metadata for a YouTube video.

import * as z from 'zod';

export default z.object({
	/* YouTube video ID. */
	id: z.string().min(1),
	/* Page and SEO title. */
	title: z.string().min(1),
	/* SEO description. */
	description: z.string().min(1),
	/* YYYY-mm-dd. */
	publishedDate: z.iso.date(),
	/* Set to false to unpublish video page (not video). */
	published: z.boolean().optional(),
	/* Tag IDs. */
	tags: z.array(z.string()).optional(),
	/* YouTube thumbnail URL. */
	thumbnailUrl: z.url().optional(),
	/* Video aspect ratio, e.g. '16 / 9'. */
	aspectRatio: z.string().min(1),
	/* OG image has different apsect ratio. */
	ogImageUrl: z.url().optional(),
	/* Video timestamps. Each timestamp has a mm:ss timestamp and a label. Max timestamp is 59:59. */
	timestamps: z
		.array(
			z.object({
				timestamp: z
					.string()
					.regex(/^\d{2}:\d{2}$/)
					.refine(
						(val) => {
							const [mins, secs] = val.split(':').map(Number);
							return mins <= 59 && secs <= 59;
						},
						{ message: 'Timestamp cannot exceed 59:59.' }
					),
				label: z.string().min(1)
			})
		)
		.optional()
});