feat: add content collection with schema and reading-time utility

- Created src/content.config.ts with Astro defineCollection using glob loader, pattern '**/*.{md,mdx}', base './src/content/posts', and Zod schema with 5 fields (title, date, type, tags, summary)
- Created src/content/posts/ directory for content storage
- Created src/utils/reading-time.ts with getReadingTime function (split whitespace, 200 WPM, Math.max(1, Math.ceil))
- All 23 new tests pass, all 61 total tests pass, npm run build succeeds

Generated with Amplifier

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
This commit is contained in:
Ken
2026-05-26 23:03:44 +00:00
parent 25fd0ea9fe
commit 2597afd472
5 changed files with 170 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';
const posts = defineCollection({
loader: glob({
pattern: '**/*.{md,mdx}',
base: './src/content/posts',
}),
schema: z.object({
title: z.string(),
date: z.coerce.date(),
type: z.enum(['post', 'pattern', 'lesson']).default('post'),
tags: z.array(z.string()).default([]),
summary: z.string().optional(),
}),
});
export const collections = { posts };
View File
+4
View File
@@ -0,0 +1,4 @@
export function getReadingTime(text: string): number {
const words = text.split(/\s+/).filter(Boolean);
return Math.max(1, Math.ceil(words.length / 200));
}