Thinkmill / keystatic

First class CMS experience, TypeScript API, Markdown & YAML/JSON based, no DB
https://keystatic.com
MIT License
1.22k stars 80 forks source link

Feature: keystaticToAstroCollections #336

Open florian-lefebvre opened 1 year ago

florian-lefebvre commented 1 year ago

As mentioned in https://youtu.be/6l2YWCyPsWk, it would be great to have a keystaticToAstroCollection utility exported by @keystatic/astro to translate the Keystatic config to the Astro collections config.

Example usage:

// src/content/config.ts
import keystaticConfig from "../../keystatic.config"
import { keystaticToAstroCollection } from "@keystatic/astro"

const keystaticCollections = keystaticToAstroCollection(keystaticConfig)

export const collections = {
    ...keystaticCollections
}

I made some experiments at the type level but collections and singletons specific types are lost once past to the config

JedWatson commented 1 year ago

πŸ’― yes this

I was looking further into astro content collections (and zod specifically) and actually think we could go both ways:

As an easy way to start with Keystatic, you can introspect the content collection types and (for the most part) convert them into keystatic collections. It would miss some features like field descriptions and labels but it'd be neat for people already using content collections and things like validation rules could mostly come across.

Then, if you're using keystatic schema (or if you migrate from zod types to keystatic to get more UI customisation) it would make sense to go the other way as well, generate content collection types from keystatic. Zod types are useful for validation / etc as well, so I don't think it would actually be limited to astro, although a high level API that exports the content collections definition like you suggest would be very neat.

Adding this to the roadmap πŸ—ΊοΈ

florian-lefebvre commented 1 year ago

Awesome! Is the roadmap public?

JedWatson commented 1 year ago

me, on slack, five minutes ago:

... feels like maybe I should write up a readme on all the stuff we've discussed / planned / ideas, but not thought through fully or implemented yet

without wanting to get too much into "making promises that could change as we learn more" I'm really keen to write something up, yeah, especially to get feedback on design / priorities of things etc. before we actually implement them

will either post something to the docs site, or a discussion, soon and let you know 🀞

JedWatson commented 1 year ago

in the meantime by the way @florian-lefebvre I know we've been a bit slow to reply to the issues you've opened in the last week, but it's great getting feedback and questions, please do keep it coming and we will get through the backlog πŸ™Œ

thanks!

florian-lefebvre commented 1 year ago

I will keep creating issues as I have feedbacks πŸ‘ Regarding the roadmap, I think you could use a simple GitHub project so that you avoid duplication and allow the community to contribute/discuss

smokeyfro commented 2 months ago

Came across this today -> https://github.com/gxjansen/Astro-CC2KS. Haven't tried it out, but looks promising.