Skip to content

Commit d450d75

Browse files
TMHSDigitalclaude
andcommitted
site: filter by licence family and by format (#45)
license-vocabulary.json groups every licence into a family and the build emits licenseFamily per entry; format-vocabulary.json groups drive a Format select (an entry matches when any of its formats is in the group). Both round-trip through the URL (?licence=, ?format=) and show as removable chips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent af4754f commit d450d75

5 files changed

Lines changed: 90 additions & 0 deletions

File tree

‎site/build.mjs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const DIST = path.join(__dirname, "dist");
2626
const CONFIG_PATH = path.join(__dirname, "config.json");
2727
const VOCAB_PATH = path.join(__dirname, "license-vocabulary.json");
2828
const SPDX_ALLOWED_PATH = path.join(__dirname, "spdx-allowed.json");
29+
const FORMATS_PATH = path.join(__dirname, "format-vocabulary.json");
2930
// Social preview image: a first-party screenshot of this site, kept with the
3031
// other first-party stills (the validator allows binaries there) and copied
3132
// into dist at build time.
@@ -51,6 +52,14 @@ function walkMarkdown(dir, out = []) {
5152
return out;
5253
}
5354

55+
/** The Licence-filter family a license value belongs to (license-vocabulary.json `families`). */
56+
function licenseFamily(vocab, license) {
57+
for (const [key, fam] of Object.entries(vocab.families || {})) {
58+
if (Array.isArray(fam.licenses) && fam.licenses.includes(license)) return key;
59+
}
60+
return "mixed";
61+
}
62+
5463
function loadEntries(vocab) {
5564
const files = walkMarkdown(CATALOG);
5665
const entries = [];
@@ -113,6 +122,8 @@ function loadEntries(vocab) {
113122
...(meta.attribution_string ? { attribution_string: String(meta.attribution_string) } : {}),
114123
...(meta.publisher ? { publisher: String(meta.publisher) } : {}),
115124
...(meta.license_spdx ? { license_spdx: String(meta.license_spdx) } : {}),
125+
...(meta.maintenance ? { maintenance: String(meta.maintenance) } : {}),
126+
licenseFamily: licenseFamily(vocab, String(meta.license)),
116127
attributionClass: vocab.licenses[String(meta.license)]?.attribution || "any",
117128
licenseRank:
118129
ATTRIBUTION_RANK[
@@ -481,6 +492,7 @@ function checkPages(files) {
481492
function main() {
482493
const config = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf8"));
483494
const vocab = JSON.parse(fs.readFileSync(VOCAB_PATH, "utf8"));
495+
const formatVocab = JSON.parse(fs.readFileSync(FORMATS_PATH, "utf8"));
484496
const { entries, errors, bodies } = loadEntries(vocab);
485497
const spdxAllowed = JSON.parse(fs.readFileSync(SPDX_ALLOWED_PATH, "utf8"));
486498
const { stacks, errors: stackErrors } = loadStacks(entries, vocab, spdxAllowed);
@@ -531,6 +543,15 @@ function main() {
531543
guides: config.guides,
532544
featured,
533545
stats,
546+
// Choices for the Licence and Format filters (app.js).
547+
filters: {
548+
licenseFamilies: Object.fromEntries(
549+
Object.entries(vocab.families || {})
550+
.filter(([key]) => !key.startsWith("_"))
551+
.map(([key, fam]) => [key, fam.label])
552+
),
553+
formatGroups: formatVocab.groups,
554+
},
534555
entries,
535556
};
536557

‎site/checks.test.mjs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,15 @@ accepts("V19 lets a tag use a word retired only as a subcategory", checkValueAli
688688
rejects("V19 rejects a tag that restates the licence", checkValueAliases("bad.md", { tags: ["cc0"] }, aliases), 'tags must not carry "cc0"');
689689
accepts("V19 keeps a tag that only mentions a licence word", checkValueAliases("ok.md", { tags: ["odbl-adjacent", "free-tier"] }, aliases));
690690

691+
/* Licence families: every licence in exactly one Licence-filter group ---- */
692+
{
693+
const fams = Object.entries(vocab.families).filter(([k]) => !k.startsWith("_"));
694+
const homeless = Object.keys(vocab.licenses).filter((l) => fams.filter(([, f]) => f.licenses.includes(l)).length !== 1);
695+
accepts("every licence value sits in exactly one family", homeless);
696+
const unknown = fams.flatMap(([, f]) => f.licenses).filter((l) => !(l in vocab.licenses));
697+
accepts("families name only licence values the vocabulary has", unknown);
698+
}
699+
691700
/* V21: tag restating the publisher ------------------------------------- */
692701
rejects("V21 rejects the publisher as a tag", checkTagsRestatePublisher("bad.md", { publisher: "Blender Studio", tags: ["blender-studio", "open-movie"] }), 'tag "blender-studio" restates publisher');
693702
accepts("V21 allows another publisher's name as a tag", checkTagsRestatePublisher("ok.md", { publisher: "Envato", tags: ["kenney-style"] }));

‎site/license-vocabulary.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@
6060
"note": "Source does not state it plainly. Pairs with status: needs-review."
6161
}
6262
},
63+
"families": {
64+
"_doc": "Groups for the site's Licence filter. Every license value above belongs to exactly one family (lib.test.mjs checks this).",
65+
"public-domain": { "label": "CC0 / public domain", "licenses": ["CC0", "Unlicense", "public-domain"] },
66+
"cc-by": { "label": "CC-BY (credit)", "licenses": ["CC-BY", "CC-BY-3.0", "CC-BY-4.0"] },
67+
"permissive": { "label": "Permissive (MIT, Apache, BSD, OFL)", "licenses": ["MIT", "ISC", "Apache-2.0", "BSD-2-Clause", "BSD-3-Clause", "SIL OFL", "CDLA-Permissive-2.0"] },
68+
"copyleft": { "label": "Copyleft (GPL, MPL, ODbL)", "licenses": ["GPL-2.0", "GPL-2.0-or-later", "GPL-3.0", "GPL-3.0-or-later", "MPL-2.0", "ODbL"] },
69+
"custom": { "label": "Publisher's own terms", "licenses": ["custom"] },
70+
"mixed": { "label": "Varies or unknown", "licenses": ["varies", "unknown"] }
71+
},
6372
"attribution_waiver_marker": "- Attribution waived:",
6473
"deprecation_reason_marker": "- Deprecated:"
6574
}

‎site/public/app.js‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323
commercialOnly: false,
2424
noAttr: false,
2525
perspective: "any",
26+
license: "any",
27+
format: "any",
2628
sort: "name",
2729
};
2830
const state = { ...DEFAULTS };
31+
// Licence families and format groups come from the build (license-vocabulary.json, format-vocabulary.json).
32+
const LICENSE_FAMILIES = data.filters?.licenseFamilies || {};
33+
const FORMAT_GROUPS = data.filters?.formatGroups || {};
2934

3035
const categoryLabels = data.categories || {};
3136
const repo = data.site?.repo || "https://github.com/TMHSDigital/Free-Game-Dev-Assets";
@@ -116,6 +121,8 @@
116121
pick("cat", "category", ["all", ...Object.keys(categoryLabels)]);
117122
pick("sort", "sort", Object.keys(SORTS));
118123
pick("view", "perspective", ["any", ...Object.keys(PERSPECTIVE_LABELS)]);
124+
pick("licence", "license", ["any", ...Object.keys(LICENSE_FAMILIES)]);
125+
pick("format", "format", ["any", ...Object.keys(FORMAT_GROUPS)]);
119126
if (p.has("q")) state.q = p.get("q");
120127
const bool = (key, field) => {
121128
const v = p.get(key);
@@ -136,6 +143,8 @@
136143
if (state.q.trim()) p.set("q", state.q.trim());
137144
if (state.sort !== DEFAULTS.sort) p.set("sort", state.sort);
138145
if (state.perspective !== DEFAULTS.perspective) p.set("view", state.perspective);
146+
if (state.license !== DEFAULTS.license) p.set("licence", state.license);
147+
if (state.format !== DEFAULTS.format) p.set("format", state.format);
139148
const bool = (key, field) => {
140149
if (state[field] !== DEFAULTS[field]) p.set(key, state[field] ? "1" : "0");
141150
};
@@ -168,6 +177,11 @@
168177
if (state.noAttr && entry.attribution_required !== false) return false;
169178
if (state.perspective !== "any" && entry.camera_perspective !== state.perspective)
170179
return false;
180+
if (state.license !== "any" && entry.licenseFamily !== state.license) return false;
181+
if (state.format !== "any") {
182+
const wanted = FORMAT_GROUPS[state.format]?.formats || [];
183+
if (!(entry.formats || []).some((f) => wanted.includes(f))) return false;
184+
}
171185
return true;
172186
}
173187

@@ -385,6 +399,10 @@
385399
key: "perspective",
386400
label: `view: ${PERSPECTIVE_LABELS[state.perspective] || state.perspective}`,
387401
});
402+
if (state.license !== DEFAULTS.license)
403+
chips.push({ key: "license", label: `licence: ${LICENSE_FAMILIES[state.license] || state.license}` });
404+
if (state.format !== DEFAULTS.format)
405+
chips.push({ key: "format", label: `format: ${FORMAT_GROUPS[state.format]?.label || state.format}` });
388406
if (!state.active) chips.push({ key: "active", label: "hiding active" });
389407
if (!state.review) chips.push({ key: "review", label: "hiding needs-review" });
390408
if (state.deprecated) chips.push({ key: "deprecated", label: "showing deprecated" });
@@ -683,6 +701,25 @@
683701
apply();
684702
});
685703

704+
const selects = [
705+
["#license-family", "license", LICENSE_FAMILIES],
706+
["#format-group", "format", Object.fromEntries(Object.entries(FORMAT_GROUPS).map(([k, g]) => [k, g.label]))],
707+
];
708+
for (const [sel, field, choices] of selects) {
709+
const el = $(sel);
710+
el.insertAdjacentHTML(
711+
"beforeend",
712+
Object.entries(choices)
713+
.map(([value, label]) => `<option value="${escapeHtml(value)}">${escapeHtml(label)}</option>`)
714+
.join("")
715+
);
716+
el.value = state[field];
717+
el.addEventListener("change", (e) => {
718+
state[field] = e.target.value;
719+
apply();
720+
});
721+
}
722+
686723
const sort = $("#sort");
687724
sort.value = state.sort;
688725
sort.addEventListener("change", (e) => {
@@ -789,6 +826,8 @@
789826
$("#filter-no-attr").checked = state.noAttr;
790827
$("#sort").value = state.sort;
791828
$("#perspective").value = state.perspective;
829+
$("#license-family").value = state.license;
830+
$("#format-group").value = state.format;
792831
}
793832

794833
/* --------------------------------------------------------------- init */

‎site/public/index.html‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ <h2 id="catalog-title">Catalog</h2>
138138
<option value="2d_flat">Flat UI</option>
139139
</select>
140140
</label>
141+
<label class="check sort-field" title="Licence family, from each entry's license field">
142+
<span>Licence</span>
143+
<select id="license-family">
144+
<option value="any">Any</option>
145+
</select>
146+
</label>
147+
<label class="check sort-field" title="Entries offering at least one of these formats">
148+
<span>Format</span>
149+
<select id="format-group">
150+
<option value="any">Any</option>
151+
</select>
152+
</label>
141153
<label class="check sort-field">
142154
<span>Sort</span>
143155
<select id="sort">

0 commit comments

Comments
 (0)