Validate YAML frontmatter and manifests
One command validates an OpenQuarry project's frontmatter and manifests. In code, each kind of file has its own validator, with one error line per problem.
npx openquarry check validates fabric.yaml, catalogue.yaml and blocks-index.json at a project's top, and under weaves/ each weave.yaml, each loom.yaml and the frontmatter of each Markdown file. To check one lesson in code, the Node command below reads scale-and-distance.md from the current folder, parses its frontmatter with the yaml package and passes it to validateThreadFrontmatter from openquarry. It needs Node 18 or later.
npm install openquarry yaml
node --input-type=module -e '
import { readFileSync } from "node:fs";
import { parse } from "yaml";
import { validateThreadFrontmatter } from "openquarry";
const text = readFileSync(process.argv[1], "utf8");
const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(text);
if (!match) throw new Error("Missing YAML frontmatter");
const result = validateThreadFrontmatter(parse(match[1]));
console.log(result);
process.exitCode = result.valid ? 0 : 1;
' scale-and-distance.mdIt prints { valid: true, errors: [] } when the lesson's frontmatter passes. It exits with a nonzero code when the frontmatter is invalid, the --- lines are missing, the file cannot be read or the YAML does not parse.
What each validator checks
validateThreadFrontmatter checks a note's or a lesson's parsed frontmatter. validateWeave checks weave.yaml, validateLoom checks loom.yaml, validateFabricManifest checks fabric.yaml and validateCatalogue checks catalogue.yaml. validateCatalogue also catches a duplicate id, a link to a subject or an entry the catalogue does not list, a home outside the entry's subjects, and a circle of links.
Add project checks for what the validators leave out: that each slug matches its file name and that every link between threads points at a thread that exists. A reviewer checks the lesson's facts and examples. The language model guide lists these checks.