Maybe I am missing the obvious, but I don’t understand how to stop site generation if I detect malformed posts. What I would like to do is to add an assert-like construct. I would like to use it for example in an include file to check for the existence of a parameter that is used within the include or in a layout file to make sure that the front matter of a post contains a specific property. Whenever the assertion fails, I would like to “throw an exception” to indicate the problem and express the solution in a descriptive way (e.g., “include X requires parameter Y, but you did not specify it”).
I think I know how to check for the existence of the parameter, but I don’t know how to stop the generation (or at least produce a warning)… I tried searching for the obvious candidates (stop/exit/throw/fail/etc.), but all I could find were countless posts, in which users had trouble getting their Jekyll installation to run.
Do you have any idea how to solve this in a non-ruby-plugin (i.e., GitHub pages compatible) way?
This sort of gets the job done. One problem I have is that the build process halts immediately on finding one error. I would like to collect a list of the errors across all pages to display at the end. I thought that liquid: error_mode: warn in _config.yml would do this, but it does not.
A very late reply, but I found this thread needing the same thing. @mdlincoln’s solution doesn’t work for Github Pages (as requested by @seb and also needed by me) because you can’t add Liquid plugins.
But you can abuse the fact that {% link ... %} will fail if the file you’re trying to link to doesn’t exist. So you can add {% link throw_missing_necessary_filed %} and as long as that page doesn’t exist you’ll get and error during generation like Liquid Exception: Could not find document ....