refactor: bookmarks becomes a content collection with auto-id

This commit is contained in:
Lewis Wynne 2026-01-29 02:10:33 +00:00
parent 23a267a242
commit 1d8ef601bc
6 changed files with 33 additions and 57 deletions

View file

@ -1,6 +1,7 @@
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { glob, file } from 'astro/loaders';
import { z } from 'astro/zod';
import yaml from 'js-yaml';
const posts = defineCollection({
loader: glob({ pattern: '**/*.md', base: './src/content/posts' }),
@ -13,4 +14,18 @@ const posts = defineCollection({
})
});
export const collections = { posts };
const bookmarks = defineCollection({
loader: file('./src/content/bookmarks.yaml', {
parser: (text) => {
const data = yaml.load(text) as Array<Record<string, unknown>>;
return data.map((item, i) => ({ id: String(i), ...item }));
},
}),
schema: z.object({
title: z.string(),
url: z.string().url(),
date: z.coerce.date(),
})
});
export const collections = { posts, bookmarks };