Is there a YAML front matter standard / validator?
Asked Answered
R

2

10

I would like to use YAML front matter as a metadata holder for a general purpose data manager, e.g.:

---
layout: "user"
title: "Mario Brega"
slug: "mario-brega"
skills:
  - fire
  - water
  - leaf
---

# Here I will be using Markdown

yes I will, _I swear_

It is used by many static generators as:


Question: is there a standard for that? Some tools that I can easily validate against, that for instance agree that all string values should be wrapped in quotes, that booleans should not, and so on.

Mapping the YAML front matter to a JSON schema would be a big plus.

Ruche answered 8/1, 2015 at 11:12 Comment(1)
There's an enhancement request for supporting YAML front matter in Markdown files for vscode-yaml that would do the trick if it's ever completedBoccioni
F
10

The closest thing to a standard would be Jekyll's Front Matter description. Everything else seems to follow that. If Jekyll didn't invent Yaml Front Matter, they were one of the first notable projects to feature it.

The YAML Lint linter has been able to verify the YAML components of every file I've thrown at it. According to the YAML spec, three-hyphens --- delimits documents; a single YAML file can contain many YAML documents. The Markdown content after the hyphen is simply dropped by the linter.

YAML is very loose and forgiving (mostly). Quoting all your strings won't hurt, but you probably don't need to bother.

The desire for some sort of baseline Markdown standard is what led to the CommonMark project.

So, while there is no formal specification, a pattern of best practices has emerged. Sticking to that pattern results in some surprisingly portable and versatile data files.

Fahy answered 14/2, 2015 at 6:25 Comment(0)
I
1

Mapping the YAML front matter to a JSON schema would be a big plus.

I thought the same, and found your question some time ago, and many years later, no solution emerged, which is quite surprised, as JAMStack frameworks exploded.

So… I was too in need of a Frontmatter YAML validator, against JSON Schema, as you would with a pure YAML or JSON file, thanks to VS Code and other tools.

During my research, I've discovered the remark linter, which can be used as a CLI, IDE extensions, or inside your markdown transformation pipeline.

I've made this remark-lint rule plugin for people with static websites to use (Gatsby, Astro, Next, Nuxt, Gridsome…):

https://github.com/JulianCataldo/remark-lint-frontmatter-schema

The docs explain the setup process, which is quite easy. I hope you, and other, will find it useful, as other linting rules of remark ecosystem.

Cheers!

Intolerant answered 9/9, 2022 at 14:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.