Open florian-lefebvre opened 1 year ago
Noted on the use case here 👍
We're pretty keen on keeping slugs static (i.e not having a function you need to call in order to know where entries live) because we need to load the content directly from GitHub over their API, and knowing that as part of static config is very helpful. The challenge with allowing a function to define it is that it becomes non-deterministic, while that's not the case in your examples above, there'd be nothing stopping you from doing:
path: () => `/content/${date.now()}/*`
... chaos 💥
However we've discussed supporting support multiple slugFields
as an alternative, which may solve the problem:
export default defineConfig({
// ...
collections: {
blog: collection({
// ...
slugFields: ['locale', 'slug'],
path: 'src/content/blog/*/*', // stars are replaced with values in order of the keys in the array above
schema: {
// ...
slug: fields.slug(/* ... */),
locale: fields.text({ label: "Locale" })
}
})
}
})
What do you think? sound useful? can you see any limitations with this approach, if we added it, that you couldn't work around?
Sounds good 👍, a few thoughts:
Right now, path
requires either *
or **
to be included. By setting the slugFields, we could pass them to the path type to force including [locale]
and [slug]
in the path. I don't know if this is possible though 🤔.
Wdyt?
I had a chat with the team today about it, and there's some nuance that we need to solve, but I've put it on the roadmap.
I like your idea about using the name of the field in the path too, we'll see what we can come up with and whether that's possible 🙂
Can you expand a bit more on what you mean by "it should be applied for usage with document fields" too?
Awesome thanks! My bad, I just checked my schema and I thought putting format: { contentField: 'document' }
changed the key to set for the path. Nevermind!
Hey @JedWatson, hope you're doing well! Do you have any ETA about this? Or could I help in any way, maybe with some guidance? It has become a must for the project I'm working on and I can dedicate a bit of time to make changes to keystatic
Sounds good 👍, a few thoughts:
- It should be also applied for usage with documents fields
- Maybe we could push this a bit further with Typescript string interpolation
Right now,
path
requires either*
or**
to be included. By setting the slugFields, we could pass them to the path type to force including[locale]
and[slug]
in the path. I don't know if this is possible though 🤔.Wdyt?
Credits to SuperKXT on Matt's TS Wizards Discord server
💎 $100 bounty created by @florian-lefebvre
👉 To claim this bounty, submit your pull request on Algora
📝 Before proceeding, please make sure you can receive payouts in your country
💵 Payment arrives in your account 2-5 days after the bounty is rewarded
💯 You keep 100% of the bounty award
🙏 Thank you for contributing to Thinkmill/keystatic!
Hi is this issue still available to be worked on? Would love to give it a shot :)
cc @JedWatson
@florian-lefebvre any updates?
nope, I'm not on the team so waiting for an answer as well
@algora-pbc Can you add a bounty label for issue?
That's a bot, I think labelling has to be done by the keystatic team if they wish
@florian-lefebvre
Is this open to work? Would love to crush this.
@JedWatson Any updates?
Current state
Currently, the path is always static except for the slug, specified by
slugField
.The problem
Projects often require more custom paths, e.g.: locales, publish date
Proposal
Make the collection config an intersection like so (pseudocode):
Examples
Locales
Publish date