1- import { defineCollection , z } from 'astro:content'
1+ import { defineCollection } from 'astro:content'
2+ import { glob } from 'astro/loaders'
3+ import { z } from 'zod'
24
35const blog = defineCollection ( {
4- type : 'content' ,
6+ loader : glob ( {
7+ pattern : '**/*.{md,mdx}' ,
8+ base : './src/content/blog' ,
9+ generateId : ( { entry } ) =>
10+ entry . replace ( / \/ i n d e x \. ( m d | m d x ) $ / , '' ) . replace ( / \. ( m d | m d x ) $ / , '' ) ,
11+ } ) ,
512 schema : ( { image } ) =>
613 z . object ( {
714 title : z . string ( ) ,
815 description : z . string ( ) . optional ( ) ,
9- date : z . coerce . date ( ) , // Transform string to Date object
16+ date : z . coerce . date ( ) ,
1017 cover : image ( ) ,
1118 language : z . string ( ) . optional ( ) ,
1219 modified : z . coerce . date ( ) . optional ( ) ,
@@ -26,7 +33,14 @@ const blog = defineCollection({
2633} )
2734
2835const pages = defineCollection ( {
29- type : 'content' ,
36+ loader : glob ( {
37+ pattern : '**/*.{md,mdx}' ,
38+ base : './src/content/pages' ,
39+ generateId : ( { entry, data } ) => {
40+ if ( data . slug && typeof data . slug === 'string' ) return data . slug
41+ return entry . replace ( / \/ i n d e x \. ( m d | m d x ) $ / , '' ) . replace ( / \. ( m d | m d x ) $ / , '' )
42+ } ,
43+ } ) ,
3044 schema : ( { image } ) =>
3145 z . object ( {
3246 title : z . string ( ) ,
@@ -37,11 +51,16 @@ const pages = defineCollection({
3751} )
3852
3953const recipes = defineCollection ( {
40- type : 'content' ,
54+ loader : glob ( {
55+ pattern : '**/*.{md,mdx}' ,
56+ base : './src/content/recipes' ,
57+ generateId : ( { entry } ) =>
58+ entry . replace ( / \/ i n d e x \. ( m d | m d x ) $ / , '' ) . replace ( / \. ( m d | m d x ) $ / , '' ) ,
59+ } ) ,
4160 schema : ( { image } ) =>
4261 z . object ( {
4362 title : z . string ( ) ,
44- date : z . coerce . date ( ) , // Transform string to Date object
63+ date : z . coerce . date ( ) ,
4564 cover : image ( ) ,
4665 description : z . string ( ) . optional ( ) ,
4766 } ) ,
0 commit comments