23 lines
829 B
JavaScript
23 lines
829 B
JavaScript
// Dev lint: page frontmatter must parse AND no unquoted scalar may carry a
|
|
// ": " sequence (the YAML plain-scalar killer found live twice today).
|
|
const fs = require("fs");
|
|
const yaml = require("js-yaml");
|
|
let bad = 0;
|
|
for (const f of fs.readdirSync("src/pages").filter((x) => x.endsWith(".md"))) {
|
|
const fm = fs.readFileSync("src/pages/" + f, "utf8").match(/^---\n([\s\S]*?)\n---\n/)[1];
|
|
fm.split("\n").forEach((l, i) => {
|
|
const m = l.match(/^(\s*[\w_]+:)( .*)$/);
|
|
if (m && !/^["'&*[\]|>@]/.test(m[2].trim()) && m[2].includes(": ")) {
|
|
console.log(`${f}:${i + 1} UNQUOTED COLON: ${m[2].trim().slice(0, 90)}`);
|
|
bad++;
|
|
}
|
|
});
|
|
try {
|
|
yaml.load(fm);
|
|
} catch (e) {
|
|
console.log(`${f}: PARSE-ERROR: ${e.reason}`);
|
|
bad++;
|
|
}
|
|
}
|
|
console.log(bad ? `${bad} problems` : "ALL FRONTMATTER CLEAN");
|