How to validate a front matter in markdown file


I have a set of markdown files that use YAML syntax for front matter . on passing these files to my jekyll project to build site , i have a set of html files generated . But if any of these files have improper front matter , they remain as .md files and not converted to html .

Now i need to validate the files for front matter before moving them into jekyll project . how can i achieve this ? is there any API or method to validate the file programmatically ?


Hi there,

First of all Jekyll should fail while executing build or serve commands if any of your pages has invalid front matter (since it must be a valid YAML snippet).

However, if that doesn’t work (for whatever reason), you can try run jekyll with --strict_front_matter switch to request additional scrutiny while generating your pages.

Here is an example how you run jekyll with the switch from command-line:

bundle exec jekyll build --strict_front_matter
bundle exec jekyll serve --strict_front_matter

Also, there is an option to enable strict mode by default in your _config.yml, here:

title: "My awesome blog"
url: ""
# enable strict front matter by default
strict_front_matter: true

Here you can find reference of additional switches/configuration flags available in Jekyll:

Hope that helps!


HI thanks for your reply , but what i need a validator program , which should check each file for front matter before i pass them to the jekyll project .

as my site gets its md files from different sources , i need to validate them for front matter before using them in my project . hope you understand my requirement now .


You can always check your files with tools like remark:


is there any such plugin in c# ?


Sorry, I can’t help but to ask why you aren’t happy with using jekyll as your validator? It will be the only answer you can trust at the end of the day - other components may diverge from Jekyll’s definition of valid front matter and that fact might (or might not) lead to obscure issues.

Anyhow, in C# you can resort to use projects like YamlDotNet, SharpYaml or ParseYaml (for hands-on experience). Also, here is the list of projects on Github you can consider as well:

Hope it helps.