I would like to build logic in to a Jekyll site so that pages of a certain layout
will have their YAML validated, with the build erroring if specific fields are missing, or have the wrong type of value, etc.
One workaround is through writing a kludgy plugin for a Liquid filter that simply takes an error message and raises an exception:
module Jekyll
module ExceptionFilter
def raise_error(msg)
bad_file = @context.registers[:page]['path']
err_msg = "On #{bad_file}: #{msg}"
raise err_msg
end
end
end
Liquid::Template.register_filter(Jekyll::ExceptionFilter)
Then, within a template, for example, I can include this:
{% unless page.necessary_field %}
{{ "You're missing necessary_field" | raise_error }}
{% endunless %}
This sort of gets the job done.
One problem I have is that the build process halts immediately on finding one error. I would love to be able to continue the build across all the .md files in the repo, and collect a list of the errors across all pages to display at the end. Based on the Jekyll docs, I thought that liquid: error_mode: warn
in _config.yml
would do this, but it does not.