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

eleventyDataSchema is not working as expected or the example is very misleading #199

Open
1oglop1 opened this issue Dec 30, 2024 · 0 comments

Comments

@1oglop1
Copy link

1oglop1 commented Dec 30, 2024

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.

So I decided to console.log data for each page and the property eleventyDataSchema was undefined.

export default function(data) {

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)

export default async function(eleventyConfig) {
// Drafts, see also _data/eleventyDataSchema.js
eleventyConfig.addPreprocessor("drafts", "*", (data, content) => {
if(data.draft && process.env.ELEVENTY_RUN_MODE === "build") {
return false;
}
});

Summary of the problems

  1. validator eleventyDataSchema.js runs on a wrong input file
  2. preprocessor drafts disables the validator
  3. using the approach from docs is not enough as long as the preprocessor is enabled

Possible fixes:

  1. update the docstrings in files with more explanation
  2. recommend https://github.com/uncenter/eleventy-plugin-validate ?
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

1 participant