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

Change content schemas to require alt text with an image #188

Open
outofambit opened this issue Apr 11, 2024 · 1 comment
Open

Change content schemas to require alt text with an image #188

outofambit opened this issue Apr 11, 2024 · 1 comment

Comments

@outofambit
Copy link
Collaborator

In our content schemas, it is possible to provide an featured image but no alt text for it. Our schemas hold them separately as in:

featuredImage: image().optional(),
featuredImageAlt: z.string().optional(),

a schema like this would prevent authors from adding an image without also including alt text:

featuredImage: z.object({
    src: image(),
    alt: z.string()
}).optional(),

which also makes it possible to provide a default with accurate alt text, as in:

featuredImage: z.object({
    src: image(),
    alt: z.string()
}).optional().default({
  src: PlaceholderImage
  alt: 'the p5 logo in a grey box'
}),
@stalgiag
Copy link
Collaborator

stalgiag commented Apr 23, 2024

This makes sense. I am the one that originally switched it from this and when I read this I was like "yeah that's a great idea. I have no idea why I changed it to begin with" but then I just tried switching to this approach and it isn't possible.

The return of "image" is much more complex than a single src string. It includes file information related to the optimization and static build and it isn't transformed into that more complex object until build time. I may be missing something but I just tried for a while and there wasn't a way to package the image() into anything other than a base property of the schema. This would explain why the Astro documentation doesn't put the image() in a property of an object.

Edit: Still trying to figure out an elegant way to do this. Could by another mistake that I am making. Will update if I find a way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants