Content Layer #935
Replies: 2 comments 1 reply
-
Defining collections of data that lives anywhereIt would be great if your content could live anywhere, and if content collections were not tied to any one folder structure. For example: // A folder full of Markdown (MDX) files
defineCollection({
name: 'blog',
data: glob('./content/blog/*.mdx'),
});
// A single file containing an array of objects
defineCollection({
name: 'authors',
data: file('./content/authors.json'),
});
// Remote data, loaded with a custom npm package
defineCollection({
name: 'articles',
data: storyblokLoader({startsWith: 'articles/posts'}),
});
// Custom data, loaded from anywhere you'd like
defineCollection({
name: 'my-custom-collection',
data: () => { /* ... */ },
}); @bholmesdev built a prototype earlier this year that seeded Astro DB from the file system, and supported watching the file system for updates. I believe that same basic API / concept could work here. Something like:
Open Questions:How is data stored in content collections? This assumes Is data stored in structured tables, or an unstructured KV JSON Document store? If stored as unstructured JSON, then we could still use Zod for schema validation, plus |
Beta Was this translation helpful? Give feedback.
-
This proposal has been accepted to stage 2: #946 Please continue the discussion there. |
Beta Was this translation helpful? Give feedback.
-
Body
Summary
Background & Motivation
Content Collections are a key primitive that brings people to Astro. Content Collections make it easy to work with local content (MD, MDX, Markdoc, etc) inside of your Astro project. They give you structure (
src/content/[collection-name]/*
), schema validation for frontmatter, and querying APIs.Goals
Example
See discussion below for examples.
Beta Was this translation helpful? Give feedback.
All reactions