Hi! I'm currently working on a free and open source CMS for Astro's Content Collections. It would be a web interface that would live parallel to your blog/website (e.g: at https://myblog.com/admin). Once authenticated, you'll be able to see all of your collections. And for each of them, you'll be able to create/edit/delete entries.
I would like to make that integration as simple as possible. Ideally, you would just have to run astro add name-of-my-integration and set the Astro output to hybrid or server. That's it.
I'm quite close to reaching that goal. My remaining problems are:
- I need to list the collections names (aka, the keys of
collectionsfromsrc/content/config.ts). This would be used to list the collections on the CMS dashboard. - I need to get the config for each collection (to know whether it's a
dataorcontentcollection, and get its Zod schema). This would be used to generate the forms to create or edit a collection's entry.
My current solution is to "pass" the entire collections object from src/content/config.ts to my integration using locals. I'm doing this using the following middleware:
import { defineMiddleware } from "astro:middleware";
import { collections } from "./content/config";
export const onRequest = defineMiddleware(
({ locals}, next) => {
locals.collections = collections;
return next();
}
);
With that, I can use Astro.locals.collections to access the collection names and config from within my integration.
I was wondering if there is any other way of doing this? It's my first integration so it's possible I've overlooked something.
Alternatively, should I consider working on a PR to add getCollections() and getCollectionConfig(collection) to Astro's Collections API?