Skip to content
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

Exporting ImageFunction from astro:content #6766

Merged
merged 1 commit into from
Apr 6, 2023
Merged

Exporting ImageFunction from astro:content #6766

merged 1 commit into from
Apr 6, 2023

Conversation

Xetera
Copy link
Contributor

@Xetera Xetera commented Apr 6, 2023

As of now, if you want to declare your schemas separate from the collection function, some hacks like these are needed:

type Schema = Parameters<typeof defineCollection>[0]['schema']

const blogSchema: Schema = ({ image }) => z.object({
  title: z.string(),
  date: z.coerce.date(),
  description: z.string(),
  tags: z.array(z.string()),
  draft: z.boolean().default(false),
  banner: image(),
})

Doing this might be needed if you want to use the schema in other places so you can export the type of the schema.

Changes

Exports the ImageFunction and gives the object passed to the schema function a name.

Testing

Just a type change so no tests should be needed.

Docs

This should be more of a QoL update and types aren't documented in general from what I know.

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Apr 6, 2023
@changeset-bot
Copy link

changeset-bot bot commented Apr 6, 2023

🦋 Changeset detected

Latest commit: 26dfc55

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

Copy link
Member

@Princesseuh Princesseuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

@Princesseuh Princesseuh merged commit 72fed68 into withastro:main Apr 6, 2023
@astrobot-houston astrobot-houston mentioned this pull request Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants