<summary>Metadata</summary>
<ul>
{entryData.description && <li>Description: {entryData.description}</li>}
+ {
+ 'publication' in entryData && entryData.publication && (
+ <li
+ data-pagefind-meta={`publication:${entryData.publication.name}`}
+ data-pagefind-filter={`publication:${entryData.publication.name}`}
+ >
+ Publication: {entryData.publication.name}{' '}
+ {entryData.publication.issue}-{entryData.publication.volume}
+ </li>
+ )
+ }
{
'rating' in entryData && entryData.rating && (
<li>Rating: {generateStarRating(entryData.rating)}</li>
>
Type: {entryData.type}
</li>
- {entryData.tags && <li>Tags: {entryData.tags.join(', ')}</li>}
+ {entryData.tags.length > 0 && <li>Tags: {entryData.tags.join(', ')}</li>}
{
entryData.posse && (
<li>
-import { defineCollection } from 'astro:content';
+import { defineCollection, type SchemaContext } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
-const baseSchema = z.object({
- title: z.string(),
- description: z.string().optional(),
- date: z.coerce.date(),
- modified: z.coerce.date().optional(),
- tags: z.array(z.string()).optional(),
- posse: z.record(z.string(), z.url()).optional(),
+const baseSchema = (image: SchemaContext['image']) =>
+ z.object({
+ title: z.string(),
+ description: z.string().optional(),
+ date: z.coerce.date(),
+ modified: z.coerce.date().optional(),
+ tags: z.array(z.string()).default([]),
+ posse: z.record(z.string(), z.url()).optional(),
+ image: image().optional(),
+ });
+
+const publication = z.object({
+ name: z.enum(['Build Weekly Roundup', 'Mine Print Hash', 'First Pass']),
+ issue: z.coerce.number().positive(),
+ volume: z.coerce.number().positive(),
});
const articles = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: 'content/articles' }),
- schema: baseSchema.extend({
- type: z.enum(['note', 'essay']),
- }),
+ schema: ({ image }) =>
+ baseSchema(image).extend({
+ type: z.enum(['essay', 'newsletter', 'note']),
+ publication: publication.optional(),
+ }),
});
const podcasts = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: 'content/podcasts' }),
- schema: baseSchema.extend({
- type: z.enum(['audio', 'video']),
- enclosure: z
- .object({
- url: z.url(),
- length: z.number(),
- type: z.string(),
- })
- .optional(),
- }),
+ schema: ({ image }) =>
+ baseSchema(image).extend({
+ type: z.enum(['audio', 'video']),
+ publication: publication.optional(),
+ enclosure: z
+ .object({
+ url: z.url(),
+ length: z.coerce.number().int().nonnegative(),
+ type: z.string(),
+ })
+ .optional(),
+ }),
});
const reviews = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: 'content/reviews' }),
- schema: baseSchema.extend({
- rating: z.int().gt(0).lte(5),
- type: z.enum(['book', 'game', 'movie', 'music', 'show']),
- }),
+ schema: ({ image }) =>
+ baseSchema(image).extend({
+ rating: z.int().gt(0).lte(5),
+ type: z.enum(['book', 'game', 'movie', 'music', 'show']),
+ }),
});
export const collections = { articles, podcasts, reviews };