eleventy-base-blog
eleventy-base-blog copied to clipboard
eleventyDataSchema is not working as expected or the example is very misleading
I am trying to learn from this repository but it took me some time to spot what was happening.
When I changed the front matter data in the fithpost.md to `draft: "no bool" but to my surprise nothing happened.
https://github.com/11ty/eleventy-base-blog/blob/940e69d2bfd522654ceefb0495931049865b9b2d/content/blog/fifthpost.md?plain=1#L4
So I decided to console.log data for each page and the property eleventyDataSchema was undefined.
https://github.com/11ty/eleventy-base-blog/blob/940e69d2bfd522654ceefb0495931049865b9b2d/_data/eleventyDataSchema.js#L4
then I logged data in the above file and found out it only runs once on this data structure and therefore can never trigger.
{
eleventy: {
version: '3.0.0',
generator: 'Eleventy v3.0.0',
env: {
source: 'cli',
runMode: 'build',
config: '/Users/.../eleventy-base-blog/eleventy.config.js',
root: '/Users/.../eleventy-base-blog'
},
directories: {
input: './content/',
inputFile: undefined,
inputGlob: undefined,
data: './_data/',
includes: './_includes/',
layouts: undefined,
output: './_site/'
}
}
}
Then I went to dig deeper in the docs and found out that this page, it should be set for each page e.g.blog/blog.11tydata.js.
According to this page https://www.11ty.dev/docs/data-validate/
https://github.com/11ty/11ty-website/blob/508e420552742a7114eec1473802a6baa43e76d0/src/docs/data-validate.md?plain=1#L1
But none of that mattered because the enabled preprocessor disables the behaviour of the validator. (Explained in preprocessor docs page) https://github.com/11ty/eleventy-base-blog/blob/940e69d2bfd522654ceefb0495931049865b9b2d/eleventy.config.js#L10-L16
Summary of the problems
- validator
eleventyDataSchema.jsruns on a wrong input file - preprocessor
draftsdisables the validator - using the approach from docs is not enough as long as the preprocessor is enabled
Possible fixes:
- update the docstrings in files with more explanation
- recommend https://github.com/uncenter/eleventy-plugin-validate ?