-
-
Notifications
You must be signed in to change notification settings - Fork 496
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
Use eleventyDataSchema
in Data Cascade to validate data
#879
Comments
You could do this with the new #1206 access to Marginally related to #867!
|
Seems related to #3251 too |
This is shipping in 3.0.0-alpha.7 as the import { z } from "zod";
import { fromZodError } from 'zod-validation-error';
export default {
eleventyDataSchema: function(data) {
let result = z.object({
draft: z.boolean().or(z.undefined()),
}).safeParse(data);
if(result.error) {
throw fromZodError(result.error);
}
}
}; |
eleventyDataSchema
in Data Cascade to validate data
Shout out to https://github.com/uncenter/eleventy-plugin-validate by @uncenter |
Thanks! While we are on this topic... is there an easier way to narrow down the source of data? I'm using |
Looks like my little hack to access specifically front matter data got removed... 70df967#r141478000. It would be nice to be able to still, maybe with an unprefixed property? |
Adding a comment here RE https://fosstodon.org/@eleventy/112446508013942858 Piggybacking on the Zod example above: Zod supports a couple of data-massaging features such as coercion and transforms, which result in the output differing from the input. It would be great to be able to take advantage of these features via (It's potentially worth noting for this use case that Zod's parse functions strip keys not found in the schema by default, but they can be kept using |
@uncenter I think you want this comment here: eleventy/src/TemplateContent.js Line 155 in d30b952
let {data} = await item.template.read(); (it should reuse the cached read promise, if any exists) |
Thank you! Updated the plugin and now it works with the latest canary! 🤩 |
Preview docs building here: https://11ty-website-git-v3-11ty.vercel.app/docs/data-validate/ |
https://www.11ty.dev/docs/config/#linters are super cool, but I was hoping to have a linter for the raw input files so I could do a front-matter linter which would throw errors or otherwise report if a file was missing a "required" field in a file's front-matter.
Is something like that possible, or should I try and do that while defining a custom collection?
Or should it be something that I write separately using glob and grey-matter as a separate script?
The text was updated successfully, but these errors were encountered: