问题
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:
- docpad.js;
- Jekyll;
- Middleman
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.
回答1:
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.
来源:https://stackoverflow.com/questions/27838730/is-there-a-yaml-front-matter-standard-validator