-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Content Collections] Add slug
frontmatter field
#5941
Conversation
🦋 Changeset detectedLatest commit: 43b6159 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking for now so we can talk about with core.
Given the timing of this, I think adding a new feature to make slug use-cases better is not the right move. We don't have time to beta test this, or to really even discuss it and understand it ourselves. I'd feel more comfortable with doing one of these two things:
|
I'm increasing feeling like (1) is the way to go. Before the change from last week we were going to tell people to use |
I understand your points! After our discord discussion, it sounds like making custom slug mapping performant will be possible with today's implementation. However, I want to highlight a few reasons this isn't ideal:
|
I can share some context/experience from having worked on the Content Collections API docs these last few days. All attempts to document this specific feature have been pretty tough, and I've been struggling to figure out what to do about:
I agree this is late in the game, but this is actually the API that I was leaning towards personally before I even saw this PR come in, so I'm a bit biased to it. It addresses the most post popular use-case for the feature in a way that is more easily made performant behind-the-scenes in future versions. I think the decision to ship an API that we're not happy with deserves special consideration, even this late in the game. It's not the end of the world if this doesn't get merged for 2.0: we could mark |
Putting aside whether this API is better or not (I think it probably is), just want to address the backwards compatible comment. We can add new reserved properties by changing how they are used within a schema, for example if we added a So we can keep things backwards compatible by adding new APIs for special use-cases rather than just modifying the existing APIs (which would not be compatible). |
I think I feel more confident given that 2 people have seen similar problems with the existing API. Given that this is about API as much as it is about perf that's a stronger reason to do the unconventional thing and make a last minute change. My previous hesitancy was based on:
So given that, I'm more neutral/positive on the change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! One bit of wording seemed too gentle, so make sure the advice to the reader is appropriate for the situation, then it's good to go!
Co-authored-by: Sarah Rainsberger <[email protected]>
Does this mean I can no longer generate slugs programmatically? I had been prepending the date to each slug: const posts = defineCollection({
slug: ({ defaultSlug, data: { pubDate } }) =>
`${formatInTimeZone(pubDate, "UTC", "yyyy/MM/dd")}/${defaultSlug}`,
…
}); Now it seems I have to manually edit this into every individual post. I guess I can work around this by using an external function |
That's what I'm planning to do. I have the opposite problem as you... I have dates prepending my markdown files, like |
@andersk @markjaquith Yes, sorry to say manual |
* feat: respect `slug` frontmatter prop * chore: replace `slug` check with proper types * fix: regen types on `slug` change * chore: add TODO on slug gen * tests: update to use `slug` frontmatter prop * chore: add error message on `slug` inside object schema * lint * chore: add note on frontmatter parse * refactor: move content errors to new heading * chore: ContentSchemaContainsSlugError * chore: changeset * docs: be 10% less gentle Co-authored-by: Sarah Rainsberger <[email protected]> * fix: avoid parsing slug on unlink * docs: clarify old API is for beta users Co-authored-by: Sarah Rainsberger <[email protected]>
Changes
slug()
collection configuration optionslug
frontmatter propertyslug
frontmatter property when presentslug
during type generationslug
from schema parsingslug
is present in a schema. Otherwise, users may attempt to use.transform()
to manipulate slugs, and be surprised when this is not respectedTesting
Update tests to use
slug
frontmatter propertyDocs