@bendyline/gezel-cli 1.0.6 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,114 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/handboek-export.ts
4
- import { existsSync } from "fs";
5
- import { cp, mkdir, writeFile } from "fs/promises";
6
- import { join, resolve } from "path";
4
+ import { existsSync as existsSync2 } from "fs";
5
+ import { cp, mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
6
+ import { join as join2, resolve } from "path";
7
+ import { SCORECARD_DATA_ATTRS as SCORECARD_DATA_ATTRS2 } from "@bendyline/gezel";
7
8
  import { CatalogService } from "@bendyline/gezel-catalog";
8
9
  import {
10
+ OG_CARD_HEIGHT,
11
+ OG_CARD_WIDTH,
9
12
  createHandboekEngine,
10
13
  findHandboekContent,
14
+ ogKicker,
15
+ readOgHeadlines,
16
+ resolveOgHeadline,
11
17
  siteDeviceInfo
12
18
  } from "@bendyline/gezel-service/handboek";
19
+ import { gezelHome } from "@bendyline/gezel/paths";
13
20
  import { generateExternalHtml, markdownDocToPlainHtml } from "@bendyline/squisq-formats/html";
14
21
  import { PLAYER_BUNDLE } from "@bendyline/squisq-react/standalone-source";
15
22
  import { markdownToDoc } from "@bendyline/squisq/doc";
16
23
  import { parseMarkdown } from "@bendyline/squisq/markdown";
17
24
 
25
+ // src/handboek-og-cards.ts
26
+ import { createHash } from "crypto";
27
+ import { existsSync } from "fs";
28
+ import { mkdir, readFile, readdir, rm, writeFile } from "fs/promises";
29
+ import { dirname, join, relative, sep } from "path";
30
+ import { isOgRendererReady, renderOgCard } from "@bendyline/gezel-service/handboek";
31
+ var MANIFEST = "manifest.json";
32
+ function ogCardPath(id) {
33
+ return `${id}.png`;
34
+ }
35
+ function specHash(plan) {
36
+ return createHash("sha256").update(plan.kicker).update("\n").update(plan.headline).digest("hex");
37
+ }
38
+ async function readManifest(dir) {
39
+ const path = join(dir, MANIFEST);
40
+ if (!existsSync(path)) return { version: 1, cards: {} };
41
+ try {
42
+ const parsed = JSON.parse(await readFile(path, "utf8"));
43
+ if (!parsed || typeof parsed.cards !== "object") throw new Error("no `cards` object");
44
+ return { version: 1, cards: parsed.cards };
45
+ } catch {
46
+ return { version: 1, cards: {} };
47
+ }
48
+ }
49
+ async function existingCardIds(dir) {
50
+ const out = [];
51
+ const walk = async (current) => {
52
+ for (const item of await readdir(current, { withFileTypes: true })) {
53
+ const full = join(current, item.name);
54
+ if (item.isDirectory()) await walk(full);
55
+ else if (item.name.endsWith(".png")) {
56
+ out.push(
57
+ relative(dir, full).split(sep).join("/").replace(/\.png$/, "")
58
+ );
59
+ }
60
+ }
61
+ };
62
+ if (existsSync(dir)) await walk(dir);
63
+ return out;
64
+ }
65
+ async function writeOgCards(opts) {
66
+ const { home, dir, plans } = opts;
67
+ if (!await isOgRendererReady(home)) {
68
+ return {
69
+ rendered: 0,
70
+ reused: 0,
71
+ swept: 0,
72
+ failed: [],
73
+ skipped: `managed Chromium is not installed under ${home} \u2014 launch the app once to let it download, then re-run`
74
+ };
75
+ }
76
+ const manifest = await readManifest(dir);
77
+ const next = { version: 1, cards: {} };
78
+ const result = { rendered: 0, reused: 0, swept: 0, failed: [] };
79
+ let done = 0;
80
+ for (const plan of plans) {
81
+ const hash = specHash(plan);
82
+ const file = join(dir, ...ogCardPath(plan.id).split("/"));
83
+ if (manifest.cards[plan.id]?.specHash === hash && existsSync(file)) {
84
+ next.cards[plan.id] = { specHash: hash };
85
+ result.reused += 1;
86
+ } else {
87
+ try {
88
+ const png = await renderOgCard(home, { kicker: plan.kicker, headline: plan.headline });
89
+ await mkdir(dirname(file), { recursive: true });
90
+ await writeFile(file, png);
91
+ next.cards[plan.id] = { specHash: hash };
92
+ result.rendered += 1;
93
+ } catch {
94
+ result.failed.push(plan.id);
95
+ }
96
+ }
97
+ done += 1;
98
+ opts.onProgress?.(done, plans.length);
99
+ }
100
+ const wanted = new Set(plans.map((p) => p.id));
101
+ for (const id of await existingCardIds(dir)) {
102
+ if (wanted.has(id)) continue;
103
+ await rm(join(dir, ...ogCardPath(id).split("/")), { force: true });
104
+ result.swept += 1;
105
+ }
106
+ await mkdir(dir, { recursive: true });
107
+ await writeFile(join(dir, MANIFEST), `${JSON.stringify(next, null, 2)}
108
+ `, "utf8");
109
+ return result;
110
+ }
111
+
18
112
  // src/handboek-site-css.ts
19
113
  var BASELINE_CSS = `:root {
20
114
  --hb-canvas: #eae5d6;
@@ -145,6 +239,18 @@ body.hb {
145
239
  .hb-sidebar h2.hb-current { color: var(--hb-ink-warm); }
146
240
  .hb-sidebar ul, .hb-onthispage ul { list-style: none; margin: 0; padding: 0; }
147
241
  .hb-sidebar li { margin: 0.15rem 0; }
242
+ .hb-sidebar .hb-sidebar-subcategory { margin-top: 0.8rem; }
243
+ .hb-sidebar .hb-sidebar-subcategory:first-child { margin-top: 0; }
244
+ .hb-sidebar .hb-sidebar-subcategory-title {
245
+ margin: 0 0 0.25rem;
246
+ font-family: var(--hb-font-ui);
247
+ font-size: 0.68rem;
248
+ font-weight: 600;
249
+ letter-spacing: 0.06em;
250
+ text-transform: uppercase;
251
+ color: var(--hb-ink-quiet);
252
+ }
253
+ .hb-sidebar .hb-sidebar-subcategory ul { padding-left: 0.45rem; }
148
254
  .hb-sidebar a, .hb-onthispage a { color: var(--hb-ink-muted); }
149
255
  .hb-sidebar a:hover, .hb-onthispage a:hover { color: var(--hb-accent); }
150
256
  .hb-sidebar a.hb-current {
@@ -257,6 +363,91 @@ body.hb {
257
363
  the description column takes the slack. */
258
364
  .hb-article tbody td:first-child { min-width: 6rem; }
259
365
 
366
+ /* Model scorecard.
367
+
368
+ The stack of test rounds is complete in the markup; assets/scorecard.js
369
+ narrows it. Everything here has to read correctly before that script runs
370
+ and after it hides most of the page, so the rounds are self-describing
371
+ panels rather than a run of headings, and the control bar reserves its own
372
+ height instead of appearing under the reader's first paragraph. */
373
+ .hb-scorecard { margin: 0 0 1.5rem; }
374
+ .hb-scorecard [hidden] { display: none !important; }
375
+ .hb-scorecard-controls:empty { display: none; }
376
+ .hb-scorecard-controlbar {
377
+ display: flex;
378
+ flex-wrap: wrap;
379
+ align-items: flex-end;
380
+ gap: 0.6rem;
381
+ padding: 0.8rem 0.9rem;
382
+ background: var(--hb-inset);
383
+ border: 1px solid var(--hb-border);
384
+ border-radius: var(--hb-radius-lg);
385
+ }
386
+ .hb-scorecard-field {
387
+ display: flex;
388
+ flex-direction: column;
389
+ gap: 0.25rem;
390
+ min-width: 0;
391
+ /* Grows to share a row, but never to the whole bar: the round picker wraps
392
+ onto its own line inside the reading measure, and a full-width control
393
+ there reads as a search field rather than as one key of four. */
394
+ flex: 1 1 9rem;
395
+ max-width: 14rem;
396
+ }
397
+ .hb-scorecard-field-label {
398
+ font-family: var(--hb-font-ui);
399
+ font-size: 0.72rem;
400
+ letter-spacing: 0.06em;
401
+ text-transform: uppercase;
402
+ color: var(--hb-ink-muted);
403
+ }
404
+ /* Keys, not capsules: --radius-md inside a --radius-lg tray, matching the
405
+ app's choice-control recipe in docs/ux.md. */
406
+ .hb-scorecard-select {
407
+ font-family: var(--hb-font-ui);
408
+ font-size: 0.9rem;
409
+ color: var(--hb-ink-warm);
410
+ background: var(--hb-panel);
411
+ border: 1px solid var(--hb-border);
412
+ border-radius: var(--hb-radius-md);
413
+ padding: 0.35rem 0.5rem;
414
+ max-width: 100%;
415
+ }
416
+ .hb-scorecard-select:hover { border-color: var(--hb-ink-quiet); }
417
+ .hb-scorecard-reset {
418
+ font-family: var(--hb-font-ui);
419
+ font-size: 0.85rem;
420
+ color: var(--hb-ink-warm);
421
+ background: var(--hb-panel);
422
+ border: 1px solid var(--hb-border);
423
+ border-radius: var(--hb-radius-md);
424
+ padding: 0.4rem 0.7rem;
425
+ cursor: pointer;
426
+ }
427
+ .hb-scorecard-reset:hover { color: var(--hb-accent); border-color: var(--hb-accent); }
428
+ .hb-scorecard-status {
429
+ font-family: var(--hb-font-ui);
430
+ font-size: 0.85rem;
431
+ color: var(--hb-ink-muted);
432
+ margin: 0.55rem 0 0;
433
+ }
434
+ .hb-article .hb-scorecard-help {
435
+ font-family: var(--hb-font-ui);
436
+ font-size: 0.82rem;
437
+ color: var(--hb-ink-quiet);
438
+ margin: 0.15rem 0 0;
439
+ }
440
+ .hb-scorecard-round { margin: 1.75rem 0 0; }
441
+ .hb-article .hb-scorecard-round-title { font-size: 1.1rem; margin-top: 0; }
442
+ .hb-article .hb-scorecard-suite-title { font-size: 0.95rem; margin: 1.25rem 0 0.5rem; }
443
+ .hb-scorecard-stamp { font-size: 0.85rem; margin: 0 0 0.75rem; }
444
+ .hb-article .hb-scorecard-withheld,
445
+ .hb-article .hb-scorecard-taskcount {
446
+ font-size: 0.82rem;
447
+ color: var(--hb-ink-muted);
448
+ margin: 0 0 0.75rem;
449
+ }
450
+
260
451
  .hb-watch { max-width: var(--hb-measure); margin: 1.25rem 0 0; font-size: 0.9rem; }
261
452
 
262
453
  /* Home */
@@ -326,8 +517,391 @@ body.hb {
326
517
  }
327
518
  `;
328
519
 
520
+ // src/handboek-site-scorecard.ts
521
+ import {
522
+ MODEL_TIER_ORDER,
523
+ SCORECARD_DATA_ATTRS,
524
+ SCORECARD_QUERY_PARAMS,
525
+ SCORECARD_ROUND_ALL,
526
+ SCORECARD_ROUND_LATEST
527
+ } from "@bendyline/gezel";
528
+ var ATTRS = SCORECARD_DATA_ATTRS;
529
+ var PARAMS = SCORECARD_QUERY_PARAMS;
530
+ var SCORECARD_FILTER_JS = `(function () {
531
+ 'use strict';
532
+
533
+ var ATTR = ${JSON.stringify(ATTRS)};
534
+ var PARAM = ${JSON.stringify(PARAMS)};
535
+ var ROUND_LATEST = ${JSON.stringify(SCORECARD_ROUND_LATEST)};
536
+ var ROUND_ALL = ${JSON.stringify(SCORECARD_ROUND_ALL)};
537
+ var TIER_ORDER = ${JSON.stringify(MODEL_TIER_ORDER)};
538
+
539
+ var ANY = '';
540
+
541
+ function attr(el, name) {
542
+ var value = el.getAttribute(name);
543
+ return value === null ? '' : value;
544
+ }
545
+
546
+ function tokens(el, name) {
547
+ var raw = attr(el, name).trim();
548
+ return raw ? raw.split(/\\s+/) : [];
549
+ }
550
+
551
+ function unique(list) {
552
+ var seen = {};
553
+ var out = [];
554
+ for (var i = 0; i < list.length; i++) {
555
+ if (list[i] && !Object.prototype.hasOwnProperty.call(seen, list[i])) {
556
+ seen[list[i]] = true;
557
+ out.push(list[i]);
558
+ }
559
+ }
560
+ return out;
561
+ }
562
+
563
+ function collect(root) {
564
+ var nodes = root.querySelectorAll('[' + ATTR.round + ']');
565
+ var rounds = [];
566
+ for (var i = 0; i < nodes.length; i++) {
567
+ var el = nodes[i];
568
+ rounds.push({
569
+ el: el,
570
+ id: attr(el, ATTR.round),
571
+ label: attr(el, ATTR.roundLabel) || attr(el, ATTR.date),
572
+ date: attr(el, ATTR.date),
573
+ hardware: attr(el, ATTR.hardware),
574
+ hardwareLabel: attr(el, ATTR.hardwareLabel) || attr(el, ATTR.hardware),
575
+ models: tokens(el, ATTR.models),
576
+ tiers: tokens(el, ATTR.tiers),
577
+ latest: el.hasAttribute(ATTR.latest)
578
+ });
579
+ }
580
+ return rounds;
581
+ }
582
+
583
+ function facets(rounds) {
584
+ var hardware = [];
585
+ var hardwareSeen = {};
586
+ var models = [];
587
+ var tiers = [];
588
+ for (var i = 0; i < rounds.length; i++) {
589
+ var round = rounds[i];
590
+ if (round.hardware && !Object.prototype.hasOwnProperty.call(hardwareSeen, round.hardware)) {
591
+ hardwareSeen[round.hardware] = true;
592
+ hardware.push({ value: round.hardware, label: round.hardwareLabel });
593
+ }
594
+ models = models.concat(round.models);
595
+ tiers = tiers.concat(round.tiers);
596
+ }
597
+ models = unique(models).sort();
598
+ tiers = unique(tiers).sort(function (a, b) {
599
+ return TIER_ORDER.indexOf(a) - TIER_ORDER.indexOf(b);
600
+ });
601
+ return { hardware: hardware, models: models, tiers: tiers };
602
+ }
603
+
604
+ /* \u2500\u2500 state \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
605
+
606
+ function readState() {
607
+ var params = new URLSearchParams(window.location.search);
608
+ return {
609
+ round: params.get(PARAM.round) || ANY,
610
+ date: params.get(PARAM.date) || ANY,
611
+ hardware: params.get(PARAM.hardware) || ANY,
612
+ model: params.get(PARAM.model) || ANY,
613
+ modelClass: params.get(PARAM.modelClass) || ANY
614
+ };
615
+ }
616
+
617
+ function narrowed(state) {
618
+ return !!(state.hardware || state.model || state.modelClass);
619
+ }
620
+
621
+ /*
622
+ * A pinned round wins; otherwise the default depends on whether the
623
+ * reader has narrowed anything. Asking for one model with the page still
624
+ * pinned to the latest round would answer "no results" whenever that
625
+ * round did not measure it \u2014 so any narrowing opens the history.
626
+ */
627
+ function scopeFor(state, rounds) {
628
+ if (state.round === ROUND_ALL) return rounds;
629
+ if (state.round === ROUND_LATEST) return latest(rounds);
630
+ if (state.round) {
631
+ return rounds.filter(function (round) {
632
+ return round.id === state.round;
633
+ });
634
+ }
635
+ if (state.date) {
636
+ return rounds.filter(function (round) {
637
+ return round.date === state.date;
638
+ });
639
+ }
640
+ return narrowed(state) ? rounds : latest(rounds);
641
+ }
642
+
643
+ function latest(rounds) {
644
+ var flagged = rounds.filter(function (round) {
645
+ return round.latest;
646
+ });
647
+ if (flagged.length > 0) return flagged;
648
+ return rounds.length > 0 ? [rounds[0]] : [];
649
+ }
650
+
651
+ /* Which option the round picker should show for the current state. */
652
+ function roundSelection(state, rounds) {
653
+ if (state.round) return state.round;
654
+ if (state.date) {
655
+ var onDate = rounds.filter(function (round) {
656
+ return round.date === state.date;
657
+ });
658
+ if (onDate.length === 1) return onDate[0].id;
659
+ return onDate.length > 0 ? ROUND_ALL : ROUND_LATEST;
660
+ }
661
+ return narrowed(state) ? ROUND_ALL : ROUND_LATEST;
662
+ }
663
+
664
+ /*
665
+ * The shortest link that reproduces exactly what is on screen.
666
+ *
667
+ * Two rules earn their complexity. A round of ROUND_LATEST or ROUND_ALL
668
+ * is written only when it is NOT what scopeFor would have defaulted to,
669
+ * because the default flips once the reader narrows something \u2014 omitting
670
+ * it on the wrong side of that flip hands out a link that opens a
671
+ * different page than the one that was shared. And a pinned round is
672
+ * written as its date whenever that date belongs to one sweep, because
673
+ * ?date=2026-08-22 is what a person would rather paste into a message;
674
+ * dates are not unique, so the run id is still written when one date
675
+ * carries two.
676
+ */
677
+ function writeState(state, rounds) {
678
+ var params = new URLSearchParams(window.location.search);
679
+ params.delete(PARAM.round);
680
+ params.delete(PARAM.date);
681
+ params.delete(PARAM.hardware);
682
+ params.delete(PARAM.model);
683
+ params.delete(PARAM.modelClass);
684
+ var defaultRound = narrowed(state) ? ROUND_ALL : ROUND_LATEST;
685
+ if (state.round === ROUND_ALL || state.round === ROUND_LATEST) {
686
+ if (state.round !== defaultRound) params.set(PARAM.round, state.round);
687
+ } else if (state.round) {
688
+ var pinned = rounds.filter(function (round) {
689
+ return round.id === state.round;
690
+ })[0];
691
+ var sharesDate = pinned
692
+ ? rounds.filter(function (round) {
693
+ return round.date === pinned.date;
694
+ }).length > 1
695
+ : true;
696
+ if (pinned && !sharesDate) params.set(PARAM.date, pinned.date);
697
+ else params.set(PARAM.round, state.round);
698
+ } else if (state.date) {
699
+ params.set(PARAM.date, state.date);
700
+ }
701
+ if (state.hardware) params.set(PARAM.hardware, state.hardware);
702
+ if (state.model) params.set(PARAM.model, state.model);
703
+ if (state.modelClass) params.set(PARAM.modelClass, state.modelClass);
704
+ var query = params.toString();
705
+ var url = window.location.pathname + (query ? '?' + query : '') + window.location.hash;
706
+ window.history.replaceState(null, '', url);
707
+ }
708
+
709
+ /* \u2500\u2500 controls \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
710
+
711
+ function option(value, label) {
712
+ var el = document.createElement('option');
713
+ el.value = value;
714
+ el.textContent = label;
715
+ return el;
716
+ }
717
+
718
+ function field(id, labelText, options) {
719
+ var wrap = document.createElement('label');
720
+ wrap.className = 'hb-scorecard-field';
721
+ var caption = document.createElement('span');
722
+ caption.className = 'hb-scorecard-field-label';
723
+ caption.textContent = labelText;
724
+ var select = document.createElement('select');
725
+ select.className = 'hb-scorecard-select';
726
+ select.id = id;
727
+ for (var i = 0; i < options.length; i++) {
728
+ select.appendChild(option(options[i].value, options[i].label));
729
+ }
730
+ wrap.appendChild(caption);
731
+ wrap.appendChild(select);
732
+ return { wrap: wrap, select: select };
733
+ }
734
+
735
+ function enhance(root) {
736
+ var mount = root.querySelector('[' + ATTR.controls + ']');
737
+ var rounds = collect(root);
738
+ if (!mount || rounds.length === 0) return;
739
+ var facet = facets(rounds);
740
+
741
+ var roundOptions = [
742
+ { value: ROUND_LATEST, label: 'Latest round' },
743
+ { value: ROUND_ALL, label: 'All rounds' }
744
+ ];
745
+ for (var i = 0; i < rounds.length; i++) {
746
+ roundOptions.push({ value: rounds[i].id, label: rounds[i].label });
747
+ }
748
+ var hardwareOptions = [{ value: ANY, label: 'Any hardware' }];
749
+ for (var h = 0; h < facet.hardware.length; h++) {
750
+ hardwareOptions.push({ value: facet.hardware[h].value, label: facet.hardware[h].label });
751
+ }
752
+ var modelOptions = [{ value: ANY, label: 'Any model' }];
753
+ for (var m = 0; m < facet.models.length; m++) {
754
+ modelOptions.push({ value: facet.models[m], label: facet.models[m] });
755
+ }
756
+ var classOptions = [{ value: ANY, label: 'Any class' }];
757
+ for (var c = 0; c < facet.tiers.length; c++) {
758
+ classOptions.push({ value: facet.tiers[c], label: facet.tiers[c] });
759
+ }
760
+
761
+ var bar = document.createElement('div');
762
+ bar.className = 'hb-scorecard-controlbar';
763
+ var hardware = field('hb-scorecard-hardware', 'Hardware', hardwareOptions);
764
+ var model = field('hb-scorecard-model', 'Model', modelOptions);
765
+ var modelClass = field('hb-scorecard-class', 'Model class', classOptions);
766
+ var round = field('hb-scorecard-round', 'Test round', roundOptions);
767
+ bar.appendChild(hardware.wrap);
768
+ bar.appendChild(model.wrap);
769
+ bar.appendChild(modelClass.wrap);
770
+ bar.appendChild(round.wrap);
771
+
772
+ var reset = document.createElement('button');
773
+ reset.type = 'button';
774
+ reset.className = 'hb-scorecard-reset';
775
+ reset.textContent = 'Reset to latest';
776
+
777
+ var status = document.createElement('p');
778
+ status.className = 'hb-scorecard-status';
779
+ status.setAttribute('role', 'status');
780
+
781
+ // Written by the script rather than into the article, because it is only
782
+ // true where the controls exist: the same prose is read in the app, where
783
+ // this page is a fixed stack of rounds with no address bar behind it.
784
+ var help = document.createElement('p');
785
+ help.className = 'hb-scorecard-help';
786
+ help.textContent =
787
+ 'Pick a machine, a model, or a round. Your choice goes into the address bar, so a link you copy opens the same view.';
788
+
789
+ mount.appendChild(bar);
790
+ mount.appendChild(status);
791
+ mount.appendChild(help);
792
+ bar.appendChild(reset);
793
+
794
+ var state = readState();
795
+
796
+ function render() {
797
+ var scope = scopeFor(state, rounds);
798
+ var inScope = {};
799
+ for (var s = 0; s < scope.length; s++) inScope[scope[s].id] = true;
800
+
801
+ var shown = 0;
802
+ for (var r = 0; r < rounds.length; r++) {
803
+ var entry = rounds[r];
804
+ var visible =
805
+ !!inScope[entry.id] &&
806
+ (!state.hardware || entry.hardware === state.hardware) &&
807
+ rowsMatch(entry.el);
808
+ entry.el.hidden = !visible;
809
+ if (visible) shown++;
810
+ }
811
+
812
+ hardware.select.value = state.hardware;
813
+ model.select.value = state.model;
814
+ modelClass.select.value = state.modelClass;
815
+ round.select.value = roundSelection(state, rounds);
816
+ reset.hidden = !state.hardware && !state.model && !state.modelClass && !state.round && !state.date;
817
+
818
+ status.textContent = shown === 0
819
+ ? 'No test rounds match these filters.'
820
+ : 'Showing ' + shown + ' of ' + rounds.length + ' test ' + (rounds.length === 1 ? 'round' : 'rounds') + '.';
821
+ writeState(state, rounds);
822
+ }
823
+
824
+ /*
825
+ * Rows and whole suite tables hide together with what they contain: a
826
+ * suite whose every row was filtered out would otherwise leave a
827
+ * heading over an empty table, which reads as "measured nothing" rather
828
+ * than "not what you asked for". Returns whether the round kept
829
+ * anything at all.
830
+ */
831
+ function rowsMatch(roundEl) {
832
+ var suites = roundEl.querySelectorAll('[' + ATTR.suite + ']');
833
+ var kept = 0;
834
+ for (var i = 0; i < suites.length; i++) {
835
+ var rows = suites[i].querySelectorAll('[' + ATTR.model + ']');
836
+ var visibleRows = 0;
837
+ for (var j = 0; j < rows.length; j++) {
838
+ var row = rows[j];
839
+ var ok =
840
+ (!state.model || attr(row, ATTR.model) === state.model) &&
841
+ (!state.modelClass || attr(row, ATTR.tier) === state.modelClass);
842
+ row.hidden = !ok;
843
+ if (ok) visibleRows++;
844
+ }
845
+ suites[i].hidden = visibleRows === 0;
846
+ if (visibleRows > 0) kept++;
847
+ }
848
+ return kept > 0;
849
+ }
850
+
851
+ function onNarrow(key, value) {
852
+ state[key] = value;
853
+ // Opening a narrower question on the latest round alone would answer
854
+ // it with whatever that one sweep happened to cover.
855
+ if (!state.round && !state.date && narrowed(state)) state.round = ROUND_ALL;
856
+ render();
857
+ }
858
+
859
+ hardware.select.addEventListener('change', function () {
860
+ onNarrow('hardware', hardware.select.value);
861
+ });
862
+ model.select.addEventListener('change', function () {
863
+ onNarrow('model', model.select.value);
864
+ });
865
+ modelClass.select.addEventListener('change', function () {
866
+ onNarrow('modelClass', modelClass.select.value);
867
+ });
868
+ round.select.addEventListener('change', function () {
869
+ state.date = ANY;
870
+ state.round = round.select.value;
871
+ render();
872
+ });
873
+ reset.addEventListener('click', function () {
874
+ state = { round: ANY, date: ANY, hardware: ANY, model: ANY, modelClass: ANY };
875
+ render();
876
+ });
877
+ window.addEventListener('popstate', function () {
878
+ state = readState();
879
+ render();
880
+ });
881
+
882
+ root.setAttribute('data-hb-scorecard-ready', '1');
883
+ render();
884
+ }
885
+
886
+ function start() {
887
+ var roots = document.querySelectorAll('[' + ATTR.root + ']');
888
+ for (var i = 0; i < roots.length; i++) enhance(roots[i]);
889
+ }
890
+
891
+ if (document.readyState === 'loading') {
892
+ document.addEventListener('DOMContentLoaded', start);
893
+ } else {
894
+ start();
895
+ }
896
+ })();
897
+ `;
898
+
329
899
  // src/handboek-export.ts
330
900
  var NAV_INLINE_MAX = 40;
901
+ var SCORECARD_SCRIPT = "scorecard.js";
902
+ function pageScripts(body) {
903
+ return body.includes(SCORECARD_DATA_ATTRS2.root) ? [SCORECARD_SCRIPT] : [];
904
+ }
331
905
  var AREA_BLURBS = {
332
906
  conceptual: "What gezel is, who your crew are, and how the pieces fit together.",
333
907
  "gezel-roles": "The roles a gezel can take, and what each one is good at.",
@@ -362,10 +936,15 @@ async function runHandboekExport(opts) {
362
936
  const stem = e.id.split("/").pop();
363
937
  if (stem && !byStem.has(stem)) byStem.set(stem, e.id);
364
938
  }
365
- await mkdir(join(out, "assets"), { recursive: true });
366
- await writeFile(join(out, "assets", "squisq-player.js"), PLAYER_BUNDLE, "utf8");
939
+ await mkdir2(join2(out, "assets"), { recursive: true });
940
+ await writeFile2(join2(out, "assets", "squisq-player.js"), PLAYER_BUNDLE, "utf8");
941
+ await writeFile2(join2(out, "assets", SCORECARD_SCRIPT), SCORECARD_FILTER_JS, "utf8");
367
942
  const skipped = [];
368
943
  let pages = 0;
944
+ const headlines = readOgHeadlines(contentDir);
945
+ const canonicalBase = normalizeBase(opts.canonicalBase);
946
+ const ogBase = opts.ogOut ? normalizeBase(opts.ogBase) : void 0;
947
+ const cardPlans = [];
369
948
  for (const entry of entries) {
370
949
  const article = await engine.article(entry.id, { mode: "site" });
371
950
  if (!article) {
@@ -378,19 +957,39 @@ async function runHandboekExport(opts) {
378
957
  const { html: body, headings } = withHeadingIds(
379
958
  wrapTables(extractBody(markdownDocToPlainHtml(parsed, { title: article.title })))
380
959
  );
381
- const dir = join(out, ...entry.id.split("/"));
382
- await mkdir(dir, { recursive: true });
383
- await writeFile(
384
- join(dir, "index.html"),
385
- articlePage({ entry, body, headings, areas, depth, css, siteUrl }),
960
+ const dir = join2(out, ...entry.id.split("/"));
961
+ await mkdir2(dir, { recursive: true });
962
+ const headline = resolveOgHeadline(entry, headlines);
963
+ if (ogBase) {
964
+ cardPlans.push({ id: entry.id, kicker: ogKicker(entry), headline });
965
+ }
966
+ const social = canonicalBase ? {
967
+ url: `${canonicalBase}${entry.id}/`,
968
+ title: entry.title,
969
+ image: ogBase ? `${ogBase}${ogCardPath(entry.id)}` : void 0,
970
+ imageAlt: headline
971
+ } : void 0;
972
+ await writeFile2(
973
+ join2(dir, "index.html"),
974
+ articlePage({
975
+ entry,
976
+ body,
977
+ headings,
978
+ areas,
979
+ depth,
980
+ css,
981
+ siteUrl,
982
+ social,
983
+ scripts: pageScripts(body)
984
+ }),
386
985
  "utf8"
387
986
  );
388
987
  const doc = markdownToDoc(parsed, {
389
988
  articleId: article.id,
390
989
  defaultDuration: article.defaultDuration ?? 6
391
990
  });
392
- await writeFile(
393
- join(dir, "watch.html"),
991
+ await writeFile2(
992
+ join2(dir, "watch.html"),
394
993
  generateExternalHtml(doc, {
395
994
  playerScriptPath: `${up(depth)}assets/squisq-player.js`,
396
995
  mode: "slideshow",
@@ -402,14 +1001,37 @@ async function runHandboekExport(opts) {
402
1001
  );
403
1002
  pages += 2;
404
1003
  }
405
- await writeFile(join(out, "index.html"), landingPage(areas, css, siteUrl), "utf8");
1004
+ const landingSocial = canonicalBase ? {
1005
+ url: canonicalBase,
1006
+ title: "The Gezel Handboek",
1007
+ image: ogBase ? `${ogBase}${ogCardPath(LANDING_CARD_ID)}` : void 0
1008
+ } : void 0;
1009
+ if (ogBase) {
1010
+ cardPlans.push({
1011
+ id: LANDING_CARD_ID,
1012
+ kicker: `${WORDMARK} \xB7 Handboek`,
1013
+ headline: "The Gezel Handboek"
1014
+ });
1015
+ }
1016
+ await writeFile2(join2(out, "index.html"), landingPage(areas, css, siteUrl, landingSocial), "utf8");
406
1017
  pages += 1;
407
- const assetsSrc = join(contentDir, "assets");
408
- if (existsSync(assetsSrc)) {
409
- await cp(assetsSrc, join(out, "assets"), { recursive: true });
1018
+ const assetsSrc = join2(contentDir, "assets");
1019
+ if (existsSync2(assetsSrc)) {
1020
+ await cp(assetsSrc, join2(out, "assets"), { recursive: true });
410
1021
  }
411
- await writeFile(join(out, "assets", "handboek.css"), BASELINE_CSS, "utf8");
412
- return { out, pages, skipped };
1022
+ await writeFile2(join2(out, "assets", "handboek.css"), BASELINE_CSS, "utf8");
1023
+ const cards = ogBase && opts.ogOut ? await writeOgCards({
1024
+ home: opts.home ?? gezelHome(),
1025
+ dir: resolve(opts.ogOut),
1026
+ plans: cardPlans
1027
+ }) : void 0;
1028
+ return { out, pages, skipped, cards };
1029
+ }
1030
+ var LANDING_CARD_ID = "index";
1031
+ function normalizeBase(base) {
1032
+ const trimmed = base?.trim();
1033
+ if (!trimmed) return void 0;
1034
+ return trimmed.endsWith("/") ? trimmed : `${trimmed}/`;
413
1035
  }
414
1036
  function rewriteSiteLinks(markdown, pageId, ids, byStem) {
415
1037
  const prefix = up(pageId.split("/").length);
@@ -477,14 +1099,43 @@ function resolveCssHref(href, depth) {
477
1099
  function cssLinks(css, depth) {
478
1100
  return [`${up(depth)}assets/handboek.css`, ...css.map((h) => resolveCssHref(h, depth))].map((href) => `<link rel="stylesheet" href="${esc(href)}">`).join("\n");
479
1101
  }
480
- function head(title, css, depth, description) {
1102
+ function socialTags(description, social) {
1103
+ const title = social.title;
1104
+ const lines = [
1105
+ `<link rel="canonical" href="${esc(social.url)}">`,
1106
+ '<meta property="og:type" content="article">',
1107
+ '<meta property="og:site_name" content="Gezel">',
1108
+ `<meta property="og:url" content="${esc(social.url)}">`,
1109
+ `<meta property="og:title" content="${esc(title)}">`,
1110
+ `<meta name="twitter:title" content="${esc(title)}">`
1111
+ ];
1112
+ if (description) {
1113
+ lines.push(`<meta property="og:description" content="${esc(description)}">`);
1114
+ lines.push(`<meta name="twitter:description" content="${esc(description)}">`);
1115
+ }
1116
+ if (social.image) {
1117
+ const alt = social.imageAlt ?? title;
1118
+ lines.push(`<meta property="og:image" content="${esc(social.image)}">`);
1119
+ lines.push(`<meta property="og:image:width" content="${OG_CARD_WIDTH}">`);
1120
+ lines.push(`<meta property="og:image:height" content="${OG_CARD_HEIGHT}">`);
1121
+ lines.push(`<meta property="og:image:alt" content="${esc(alt)}">`);
1122
+ lines.push(`<meta name="twitter:image" content="${esc(social.image)}">`);
1123
+ lines.push(`<meta name="twitter:image:alt" content="${esc(alt)}">`);
1124
+ }
1125
+ lines.push(
1126
+ `<meta name="twitter:card" content="${social.image ? "summary_large_image" : "summary"}">`
1127
+ );
1128
+ return `
1129
+ ${lines.join("\n")}`;
1130
+ }
1131
+ function head(title, css, depth, description, social) {
481
1132
  return `<!DOCTYPE html>
482
1133
  <html lang="en">
483
1134
  <head>
484
1135
  <meta charset="UTF-8">
485
1136
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
486
1137
  <title>${esc(title)}</title>${description ? `
487
- <meta name="description" content="${esc(description)}">` : ""}
1138
+ <meta name="description" content="${esc(description)}">` : ""}${social ? socialTags(description, social) : ""}
488
1139
  ${cssLinks(css, depth)}
489
1140
  </head>`;
490
1141
  }
@@ -511,12 +1162,7 @@ function sidebar(areas, entry, depth) {
511
1162
  const sections = areas.map((area) => {
512
1163
  const isCurrent = area.area === entry.area;
513
1164
  const items = isCurrent && area.entries.length <= NAV_INLINE_MAX ? area.entries : isCurrent ? dedupeById([...area.entries.filter((e) => e.id === areaLanding(area)), entry]) : [];
514
- const list = items.length ? `<ul>
515
- ${items.map((e) => {
516
- const current = e.id === entry.id ? ' class="hb-current" aria-current="page"' : "";
517
- return `<li><a${current} href="${up(depth)}${esc(e.id)}/">${esc(e.title)}</a></li>`;
518
- }).join("\n")}
519
- </ul>` : "";
1165
+ const list = items.length ? sidebarEntryList(items, entry.id, depth) : "";
520
1166
  const more = isCurrent && area.entries.length > NAV_INLINE_MAX ? `<p class="hb-more"><a href="${up(depth)}${esc(areaLanding(area))}/">All ${area.entries.length} ${esc(area.title.toLowerCase())}</a></p>` : "";
521
1167
  const heading = isCurrent ? `<h2 class="hb-current">${esc(area.title)}</h2>` : `<h2><a href="${up(depth)}${esc(areaLanding(area))}/">${esc(area.title)}</a></h2>`;
522
1168
  return `<section>
@@ -531,6 +1177,40 @@ ${sections.join("\n")}
531
1177
  </nav>
532
1178
  </aside>`;
533
1179
  }
1180
+ function sidebarEntryList(entries, currentId, depth) {
1181
+ const ungrouped = [];
1182
+ const grouped = /* @__PURE__ */ new Map();
1183
+ for (const entry of entries) {
1184
+ if (!entry.subcategory) {
1185
+ ungrouped.push(entry);
1186
+ continue;
1187
+ }
1188
+ const existing = grouped.get(entry.subcategory.id);
1189
+ if (existing) {
1190
+ existing.entries.push(entry);
1191
+ } else {
1192
+ grouped.set(entry.subcategory.id, { ...entry.subcategory, entries: [entry] });
1193
+ }
1194
+ }
1195
+ const items = ungrouped.map((entry) => sidebarEntryLink(entry, currentId, depth));
1196
+ for (const group of [...grouped.values()].sort(
1197
+ (a, b) => a.order - b.order || a.title.localeCompare(b.title)
1198
+ )) {
1199
+ items.push(`<li class="hb-sidebar-subcategory">
1200
+ <h3 class="hb-sidebar-subcategory-title">${esc(group.title)}</h3>
1201
+ <ul>
1202
+ ${group.entries.map((entry) => sidebarEntryLink(entry, currentId, depth)).join("\n")}
1203
+ </ul>
1204
+ </li>`);
1205
+ }
1206
+ return `<ul class="hb-sidebar-entries">
1207
+ ${items.join("\n")}
1208
+ </ul>`;
1209
+ }
1210
+ function sidebarEntryLink(entry, currentId, depth) {
1211
+ const current = entry.id === currentId ? ' class="hb-current" aria-current="page"' : "";
1212
+ return `<li><a${current} href="${up(depth)}${esc(entry.id)}/">${esc(entry.title)}</a></li>`;
1213
+ }
534
1214
  function dedupeById(list) {
535
1215
  const seen = /* @__PURE__ */ new Set();
536
1216
  return list.filter((e) => !seen.has(e.id) && seen.add(e.id));
@@ -548,10 +1228,11 @@ ${items}
548
1228
  </aside>`;
549
1229
  }
550
1230
  function articlePage(args) {
551
- const { entry, body, headings, areas, depth, css, siteUrl } = args;
1231
+ const { entry, body, headings, areas, depth, css, siteUrl, social, scripts } = args;
552
1232
  const area = areas.find((a) => a.area === entry.area);
553
1233
  const aside = onThisPage(headings);
554
- return `${head(`${entry.title} \u2014 Gezel Handboek`, css, depth, entry.summary)}
1234
+ const scriptTags = scripts.map((name) => `<script defer src="${up(depth)}assets/${esc(name)}"></script>`).join("\n");
1235
+ return `${head(`${entry.title} \u2014 Gezel Handboek`, css, depth, entry.summary, social)}
555
1236
  <body class="hb hb-article-page">
556
1237
  ${masthead(areas, depth, siteUrl, entry.area)}
557
1238
  <div class="hb-layout">
@@ -568,6 +1249,7 @@ ${body}
568
1249
  ${aside}
569
1250
  </div>
570
1251
  ${footer(depth)}
1252
+ ${scriptTags}
571
1253
  </body>
572
1254
  </html>`;
573
1255
  }
@@ -576,7 +1258,7 @@ function footer(depth) {
576
1258
  <p><a href="${up(depth)}">Gezel Handboek</a> \u2014 documentation for gezel, a crew of AI companions that works for you, from your own computer.</p>
577
1259
  </footer>`;
578
1260
  }
579
- function landingPage(areas, css, siteUrl) {
1261
+ function landingPage(areas, css, siteUrl, social) {
580
1262
  const byId = new Map(areas.flatMap((a) => a.entries).map((e) => [e.id, e]));
581
1263
  const startHere = START_HERE.map((id) => byId.get(id)).filter(
582
1264
  (e) => e !== void 0
@@ -603,7 +1285,7 @@ ${list}
603
1285
  <p class="hb-more"><a href="${esc(landing)}/">Browse all ${area.entries.length} ${esc(area.title.toLowerCase())}</a></p>
604
1286
  </section>`;
605
1287
  }).join("\n");
606
- return `${head("Gezel Handboek", css, 0, "Documentation for gezel \u2014 a crew of AI companions that works for you, from your own computer.")}
1288
+ return `${head("Gezel Handboek", css, 0, "Documentation for gezel \u2014 a crew of AI companions that works for you, from your own computer.", social)}
607
1289
  <body class="hb hb-home">
608
1290
  ${masthead(areas, 0, siteUrl)}
609
1291
  <main class="hb-main hb-home-main">
@@ -622,6 +1304,7 @@ ${footer(0)}
622
1304
  }
623
1305
  export {
624
1306
  extractBody,
1307
+ pageScripts,
625
1308
  resolveCssHref,
626
1309
  rewriteSiteLinks,
627
1310
  runHandboekExport,