Skip to content

Commit 215ddf8

Browse files
TMHSDigitalclaude
andcommitted
Type-check list and boolean fields, strip trailing frontmatter comments, one link-scheme rule, build-time duplicate id check
- frontmatter: a trailing ' # comment' is dropped outside quotes (#79); a comment or blank line between a key and its block list no longer breaks the list (#84); TEMPLATE.md moves its inline guidance to comment lines - validate: new V24 checkFieldTypes rejects tags/subcategories/formats that parsed as text and quoted booleans, with the fix in the message (#79) - shared: EXTERNAL_SCHEME_RE and ANY_SCHEME_RE used by validate, the link resolver and the page checks; an ftp:/data:/javascript: link is rejected everywhere with the scheme named; a line-start autolink is not raw HTML (#83) - build: a duplicate id fails the build instead of overwriting a page (#81) Closes #79, #81, #83, #84 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 5e064fc commit 215ddf8

11 files changed

Lines changed: 500 additions & 370 deletions

File tree

‎catalog/TEMPLATE.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ commercial: true
1111
attribution_required: false
1212
formats: [glTF, FBX, PNG]
1313
# subcategories and formats spelling: see CONTRIBUTING.md (formats must be in site/format-vocabulary.json)
14-
tags: [low-poly, modular] # describe the content; never the licence or the publisher (V19, V21)
15-
verified: 2026-07-19 # the day you read the licence at the source
16-
status: needs-review # set active once the licence is read and quoted in ## Evidence
14+
# tags describe the content; never the licence or the publisher (V19, V21)
15+
tags: [low-poly, modular]
16+
# verified: the day you read the licence at the source
17+
verified: 2026-07-19
18+
# status: set active once the licence is read and quoted in ## Evidence
19+
status: needs-review
1720
# Optional (omit if N/A):
1821
# publisher: Kenney # rights holder when that publisher has more than one entry; not a generic host
1922
# attribution_string: "Credit line" # required when attribution_required is true

‎site/build.mjs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ function loadEntries(vocab) {
5151
const entries = [];
5252
const errors = [];
5353
const bodies = new Map();
54+
// validate.mjs catches a duplicate id too, but a local `npm run build` must
55+
// not quietly write one entry's page over another's.
56+
const fileOfId = new Map();
5457

5558
for (const file of files) {
5659
const text = fs.readFileSync(file, "utf8");
@@ -72,6 +75,11 @@ function loadEntries(vocab) {
7275
errors.push(`${rel} missing: ${missing.join(", ")}`);
7376
continue;
7477
}
78+
if (fileOfId.has(String(meta.id))) {
79+
errors.push(`duplicate id "${meta.id}": ${fileOfId.get(String(meta.id))} and ${rel}`);
80+
continue;
81+
}
82+
fileOfId.set(String(meta.id), rel);
7583
bodies.set(String(meta.id), body);
7684

7785
entries.push({

‎site/checks.mjs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,38 @@ export function checkPublisherConsistency(entries) {
236236
return errors;
237237
}
238238

239+
/* ----------------------------------------------------------------- V24 */
240+
/** Fields that must parse as YAML lists. `hardware_tags` is checked in V12. */
241+
const LIST_FIELDS = ["subcategories", "formats", "tags"];
242+
/** Fields that must parse as booleans, plus the literal words each one also allows. */
243+
const BOOLEAN_FIELDS = { commercial: ["varies", "unknown"], attribution_required: ["unknown"] };
244+
245+
/**
246+
* The list fields were checked for emptiness but never for being lists, and
247+
* the two boolean fields accepted the quoted strings "true"/"false". A
248+
* trailing comment or a pair of quotes then produced an entry that passed
249+
* validation with no tags, or with "commercial ?" on its card.
250+
*/
251+
export function checkFieldTypes(rel, meta) {
252+
const errors = [];
253+
for (const field of LIST_FIELDS) {
254+
const v = meta[field];
255+
if (empty(v) || Array.isArray(v)) continue;
256+
errors.push(`${rel} ${field} must be a list like [a, b] or one "- item" per line; got the text "${String(v)}"`);
257+
}
258+
for (const [field, words] of Object.entries(BOOLEAN_FIELDS)) {
259+
const v = meta[field];
260+
if (empty(v) || typeof v === "boolean" || words.includes(v)) continue;
261+
const s = String(v);
262+
if (s === "true" || s === "false") {
263+
errors.push(`${rel} ${field} "${s}" is quoted text, not a boolean; write ${field}: ${s} without quotes`);
264+
} else {
265+
errors.push(`${rel} ${field} "${s}" is not true|false|${words.join("|")}`);
266+
}
267+
}
268+
return errors;
269+
}
270+
239271
/* ----------------------------------------------------------------- V12 */
240272
/** Documented values for the optional 2D/UI taxonomy. See catalog/TEMPLATE.md. */
241273
export const CAMERA_PERSPECTIVES = new Set([

‎site/checks.test.mjs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
checkEngineFields,
2020
checkEntryUrl,
2121
checkEvidenceDates,
22+
checkFieldTypes,
2223
checkFormatVocabulary,
2324
evidenceDates,
2425
markdownAnchors,
@@ -748,6 +749,16 @@ accepts(
748749
formatVocab.formats.filter((f) => Object.prototype.hasOwnProperty.call(aliases.formats, f))
749750
);
750751

752+
/* V24: field types (#79) ------------------------------------------------ */
753+
rejects("V24 rejects tags that parsed as text", checkFieldTypes("bad.md", { tags: "[a, b] # note" }), "tags must be a list");
754+
rejects("V24 rejects a subcategories string", checkFieldTypes("bad.md", { subcategories: "models" }), "subcategories must be a list");
755+
rejects("V24 rejects a quoted boolean", checkFieldTypes("bad.md", { commercial: "true" }), "write commercial: true without quotes");
756+
rejects("V24 rejects a quoted attribution_required", checkFieldTypes("bad.md", { attribution_required: "false" }), "write attribution_required: false without quotes");
757+
rejects("V24 rejects an unknown commercial word", checkFieldTypes("bad.md", { commercial: "maybe" }), 'commercial "maybe" is not true|false|varies|unknown');
758+
accepts("V24 accepts lists and booleans", checkFieldTypes("ok.md", { tags: ["a"], subcategories: ["b"], formats: ["PNG"], commercial: true, attribution_required: false }));
759+
accepts("V24 accepts the literal words", checkFieldTypes("ok.md", { commercial: "varies", attribution_required: "unknown" }));
760+
accepts("V24 leaves missing fields to the required check", checkFieldTypes("ok.md", {}));
761+
751762
/* ----------------------------------------------------------------------- */
752763
if (failures.length) {
753764
console.error(`checks.test failed (${failures.length}):`);

‎site/lib/frontmatter.mjs‎

Lines changed: 158 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,158 @@
1-
/**
2-
* Entry frontmatter and body helpers, shared by build.mjs and validate.mjs so
3-
* the two can never read the same file differently. (They used to carry a
4-
* copy each, and the copies had drifted: one undid quote escapes and the
5-
* other did not.)
6-
*
7-
* The parser reads exactly the YAML subset entries use: `key: value`, quoted
8-
* scalars, flow lists (`[a, "b, c"]`), block lists (`key:` then ` - item`)
9-
* and `#` comment lines. Anything else, and a key given twice, is reported
10-
* with its line number rather than guessed at.
11-
*/
12-
import { renderInline } from "./markdown.mjs";
13-
import { unquoteScalar } from "./shared.mjs";
14-
15-
/** Splits the inside of a flow list on commas that are not inside quotes. */
16-
function splitFlowList(inner) {
17-
const parts = [];
18-
let cur = "";
19-
let quote = null;
20-
for (let i = 0; i < inner.length; i += 1) {
21-
const ch = inner[i];
22-
if (quote) {
23-
cur += ch;
24-
if (quote === '"' && ch === "\\" && i + 1 < inner.length) cur += inner[++i];
25-
else if (ch === quote) quote = null;
26-
} else if (ch === '"' || ch === "'") {
27-
quote = ch;
28-
cur += ch;
29-
} else if (ch === ",") {
30-
parts.push(cur);
31-
cur = "";
32-
} else cur += ch;
33-
}
34-
parts.push(cur);
35-
return parts.map((p) => unquoteScalar(p.trim()));
36-
}
37-
38-
export function parseScalar(raw) {
39-
const v = raw.trim();
40-
if (v === "true") return true;
41-
if (v === "false") return false;
42-
if (v === "null" || v === "~" || v === "") return null;
43-
if (v.length >= 2 && ((v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'")))) {
44-
return unquoteScalar(v);
45-
}
46-
if (v.startsWith("[") && v.endsWith("]")) {
47-
const inner = v.slice(1, -1).trim();
48-
return inner ? splitFlowList(inner) : [];
49-
}
50-
return v;
51-
}
52-
53-
/**
54-
* `{ meta, body, errors }`, or null when the text has no frontmatter block.
55-
* `errors` are "line N: ..." strings; the caller prefixes the file.
56-
*/
57-
export function parseFrontmatter(text) {
58-
// A byte-order mark is invisible in an editor; ignore it.
59-
const match = String(text)
60-
.replace(/^/, "")
61-
.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?$/);
62-
if (!match) return null;
63-
const meta = {};
64-
const errors = [];
65-
const lines = match[1].split(/\r?\n/);
66-
let listKey = null;
67-
lines.forEach((line, i) => {
68-
const lineNo = i + 2; // line 1 is the opening ---
69-
if (!line.trim() || line.trim().startsWith("#")) return;
70-
const item = line.match(/^\s+-\s+(.*)$/);
71-
if (item) {
72-
if (listKey === null) errors.push(`line ${lineNo}: list item without a key above it`);
73-
else meta[listKey].push(parseScalar(item[1]));
74-
return;
75-
}
76-
listKey = null;
77-
const idx = line.indexOf(":");
78-
if (idx === -1 || /^\s/.test(line)) {
79-
errors.push(`line ${lineNo}: "${line.trim()}" is not a key: value line`);
80-
return;
81-
}
82-
const key = line.slice(0, idx).trim();
83-
if (Object.prototype.hasOwnProperty.call(meta, key)) {
84-
errors.push(`line ${lineNo}: key "${key}" is given twice`);
85-
return;
86-
}
87-
const value = parseScalar(line.slice(idx + 1));
88-
const next = lines[i + 1];
89-
if (value === null && next !== undefined && /^\s+-\s/.test(next)) {
90-
meta[key] = [];
91-
listKey = key;
92-
return;
93-
}
94-
meta[key] = value;
95-
});
96-
return { meta, body: match[2] || "", errors };
97-
}
98-
99-
/** The `## Evidence` section of an entry body, up to the next `## ` heading, or null. */
100-
export function evidenceSection(body) {
101-
const idx = body.search(/^## Evidence\s*$/m);
102-
if (idx === -1) return null;
103-
const rest = body.slice(idx);
104-
const next = rest.search(/\n## (?!Evidence\s*$)/m);
105-
return next === -1 ? rest : rest.slice(0, next);
106-
}
107-
108-
const ENTITIES = { "&amp;": "&", "&lt;": "<", "&gt;": ">", "&quot;": '"', "&#39;": "'" };
109-
110-
/**
111-
* Plain text of a line of entry markdown. It goes through the same inline
112-
* renderer as the entry page and drops the tags, so it strips exactly the
113-
* markup the page renders: underscores and `#` stay literal (Rig_Medium, C#).
114-
*/
115-
export function plainText(markdown) {
116-
const html = renderInline(markdown, (href) => ({ href, external: true }));
117-
return html
118-
.replace(/<[^>]+>/g, "")
119-
.replace(/&(amp|lt|gt|quot|#39);/g, (m) => ENTITIES[m])
120-
.replace(/\s+/g, " ")
121-
.trim();
122-
}
123-
124-
/** The first paragraph of an entry body as plain text, at most 220 characters. */
125-
export function summaryFromBody(body) {
126-
const first =
127-
String(body)
128-
.split(/\n\s*\n/)
129-
.map((p) => p.trim())
130-
.find((p) => p && !p.startsWith("#")) || "";
131-
const clean = plainText(first);
132-
return clean.length > 220 ? `${clean.slice(0, 217)}…` : clean;
133-
}
1+
/**
2+
* Entry frontmatter and body helpers, shared by build.mjs and validate.mjs so
3+
* the two can never read the same file differently. (They used to carry a
4+
* copy each, and the copies had drifted: one undid quote escapes and the
5+
* other did not.)
6+
*
7+
* The parser reads exactly the YAML subset entries use: `key: value`, quoted
8+
* scalars, flow lists (`[a, "b, c"]`), block lists (`key:` then ` - item`)
9+
* and `#` comment lines. Anything else, and a key given twice, is reported
10+
* with its line number rather than guessed at.
11+
*/
12+
import { renderInline } from "./markdown.mjs";
13+
import { unquoteScalar } from "./shared.mjs";
14+
15+
/** Splits the inside of a flow list on commas that are not inside quotes. */
16+
function splitFlowList(inner) {
17+
const parts = [];
18+
let cur = "";
19+
let quote = null;
20+
for (let i = 0; i < inner.length; i += 1) {
21+
const ch = inner[i];
22+
if (quote) {
23+
cur += ch;
24+
if (quote === '"' && ch === "\\" && i + 1 < inner.length) cur += inner[++i];
25+
else if (ch === quote) quote = null;
26+
} else if (ch === '"' || ch === "'") {
27+
quote = ch;
28+
cur += ch;
29+
} else if (ch === ",") {
30+
parts.push(cur);
31+
cur = "";
32+
} else cur += ch;
33+
}
34+
parts.push(cur);
35+
return parts.map((p) => unquoteScalar(p.trim()));
36+
}
37+
38+
/**
39+
* Drops a trailing ` # comment`. As in YAML, a `#` starts a comment only after
40+
* whitespace (or at the start) and outside quotes, so `C#` and `#fff` are
41+
* content. A quote opens only where a scalar can start (the start, or after
42+
* `[`, `,` or whitespace), so an apostrophe in `Kay's` is content too.
43+
*/
44+
function stripComment(raw) {
45+
let quote = null;
46+
for (let i = 0; i < raw.length; i += 1) {
47+
const ch = raw[i];
48+
if (quote) {
49+
if (quote === '"' && ch === "\\") i += 1;
50+
else if (ch === quote) quote = null;
51+
} else if ((ch === '"' || ch === "'") && (i === 0 || /[\s[,]/.test(raw[i - 1]))) {
52+
quote = ch;
53+
} else if (ch === "#" && (i === 0 || /\s/.test(raw[i - 1]))) {
54+
return raw.slice(0, i);
55+
}
56+
}
57+
return raw;
58+
}
59+
60+
export function parseScalar(raw) {
61+
const v = stripComment(raw).trim();
62+
if (v === "true") return true;
63+
if (v === "false") return false;
64+
if (v === "null" || v === "~" || v === "") return null;
65+
if (v.length >= 2 && ((v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'")))) {
66+
return unquoteScalar(v);
67+
}
68+
if (v.startsWith("[") && v.endsWith("]")) {
69+
const inner = v.slice(1, -1).trim();
70+
return inner ? splitFlowList(inner) : [];
71+
}
72+
return v;
73+
}
74+
75+
/**
76+
* `{ meta, body, errors }`, or null when the text has no frontmatter block.
77+
* `errors` are "line N: ..." strings; the caller prefixes the file.
78+
*/
79+
export function parseFrontmatter(text) {
80+
// A byte-order mark is invisible in an editor; ignore it.
81+
const match = String(text)
82+
.replace(/^/, "")
83+
.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n([\s\S]*))?$/);
84+
if (!match) return null;
85+
const meta = {};
86+
const errors = [];
87+
const lines = match[1].split(/\r?\n/);
88+
let listKey = null;
89+
lines.forEach((line, i) => {
90+
const lineNo = i + 2; // line 1 is the opening ---
91+
if (!line.trim() || line.trim().startsWith("#")) return;
92+
const item = line.match(/^\s+-\s+(.*)$/);
93+
if (item) {
94+
if (listKey === null) errors.push(`line ${lineNo}: list item without a key above it`);
95+
else meta[listKey].push(parseScalar(item[1]));
96+
return;
97+
}
98+
listKey = null;
99+
const idx = line.indexOf(":");
100+
if (idx === -1 || /^\s/.test(line)) {
101+
errors.push(`line ${lineNo}: "${line.trim()}" is not a key: value line`);
102+
return;
103+
}
104+
const key = line.slice(0, idx).trim();
105+
if (Object.prototype.hasOwnProperty.call(meta, key)) {
106+
errors.push(`line ${lineNo}: key "${key}" is given twice`);
107+
return;
108+
}
109+
const value = parseScalar(line.slice(idx + 1));
110+
// A block list may start after blank or comment lines under its key.
111+
let j = i + 1;
112+
while (j < lines.length && (!lines[j].trim() || lines[j].trim().startsWith("#"))) j += 1;
113+
const next = lines[j];
114+
if (value === null && next !== undefined && /^\s+-\s/.test(next)) {
115+
meta[key] = [];
116+
listKey = key;
117+
return;
118+
}
119+
meta[key] = value;
120+
});
121+
return { meta, body: match[2] || "", errors };
122+
}
123+
124+
/** The `## Evidence` section of an entry body, up to the next `## ` heading, or null. */
125+
export function evidenceSection(body) {
126+
const idx = body.search(/^## Evidence\s*$/m);
127+
if (idx === -1) return null;
128+
const rest = body.slice(idx);
129+
const next = rest.search(/\n## (?!Evidence\s*$)/m);
130+
return next === -1 ? rest : rest.slice(0, next);
131+
}
132+
133+
const ENTITIES = { "&amp;": "&", "&lt;": "<", "&gt;": ">", "&quot;": '"', "&#39;": "'" };
134+
135+
/**
136+
* Plain text of a line of entry markdown. It goes through the same inline
137+
* renderer as the entry page and drops the tags, so it strips exactly the
138+
* markup the page renders: underscores and `#` stay literal (Rig_Medium, C#).
139+
*/
140+
export function plainText(markdown) {
141+
const html = renderInline(markdown, (href) => ({ href, external: true }));
142+
return html
143+
.replace(/<[^>]+>/g, "")
144+
.replace(/&(amp|lt|gt|quot|#39);/g, (m) => ENTITIES[m])
145+
.replace(/\s+/g, " ")
146+
.trim();
147+
}
148+
149+
/** The first paragraph of an entry body as plain text, at most 220 characters. */
150+
export function summaryFromBody(body) {
151+
const first =
152+
String(body)
153+
.split(/\n\s*\n/)
154+
.map((p) => p.trim())
155+
.find((p) => p && !p.startsWith("#")) || "";
156+
const clean = plainText(first);
157+
return clean.length > 220 ? `${clean.slice(0, 217)}…` : clean;
158+
}

0 commit comments

Comments
 (0)