Skip to content

Instantly share code, notes, and snippets.

@ddotx
Created March 12, 2025 14:23
Show Gist options
  • Save ddotx/0e69dfc691779235d1a8bd25cc6a53f1 to your computer and use it in GitHub Desktop.
Save ddotx/0e69dfc691779235d1a8bd25cc6a53f1 to your computer and use it in GitHub Desktop.
import { file, glob } from "astro/loaders";
import { defineCollection, z } from "astro:content";
export const collections = {
posts: defineCollection({
loader: glob({
pattern: "src/data/posts/**/*.md"
}),
}),
products: defineCollection({
loader: file("src/data/products.json", {
parser: (p) => JSON.parse(p).data,
}),
schema: z.object({
id: z.number(),
documentId: z.string(),
title: z.string(),
image: z.string().optional(),
SKU: z.string(),
cover_image: z.object({
url: z.string(),
})
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment