@dogsbay/docs-layout 0.2.0-beta.16 → 0.2.0-beta.161

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.
@@ -28,10 +28,35 @@ import type { TaxonomyDisplay } from "@dogsbay/types";
28
28
 
29
29
  interface Props {
30
30
  /**
31
- * Path prefix where Pagefind's index lives. Default: "/pagefind/".
32
- * Override when a site uses a non-root base path (e.g. "/docs/pagefind/").
31
+ * Path where Pagefind's index lives, e.g. `/pagefind/` or
32
+ * `/<repo>/pagefind/` for subpath-mounted deploys. NO DEFAULT —
33
+ * a host-root default would silently 404 on subpath deploys
34
+ * (GH Pages project pages, multi-mount Cloudflare). The
35
+ * format-astro emitter passes the combined-prefix-aware URL;
36
+ * manual instantiations must do the same. When undefined, the
37
+ * search dialog throws on first open with a clear console error.
33
38
  */
34
39
  pagefindUrl?: string;
40
+ /**
41
+ * The base Pagefind prefixes result URLs with. Pagefind's own default is
42
+ * the folder above the bundle, which is right for GitHub Pages project
43
+ * sites and doubles the prefix on Workers subpath mounts (their index
44
+ * already carries the mount). format-astro computes the right value per
45
+ * layout; when absent, Pagefind's default is left alone. See
46
+ * `pagefind-base-url.ts`.
47
+ */
48
+ pagefindBaseUrl?: string;
49
+ /**
50
+ * URL of the site's `nav.json` (typically `${basePath}/_dogsbay/nav.json`).
51
+ * Used to render hierarchical facets in document order: when the
52
+ * `category` facet (or any taxonomy flagged `hierarchical: true`)
53
+ * is segment-encoded — i.e. its values are individual path segments
54
+ * not slash-joined — the tree shape is derived from nav. Without
55
+ * `navUrl`, hierarchical segment-encoded facets fall back to a flat
56
+ * list (still functional, just no tree structure). Slash-encoded
57
+ * taxonomies don't need nav and build trees from their values directly.
58
+ */
59
+ navUrl?: string;
35
60
  /** Placeholder text for the search input */
36
61
  placeholder?: string;
37
62
  /**
@@ -41,19 +66,38 @@ interface Props {
41
66
  * back to slugs when undefined.
42
67
  */
43
68
  taxonomyDisplay?: Record<string, TaxonomyDisplay>;
69
+ /**
70
+ * Current page's product (namespace) and version. On a multi-product /
71
+ * versioned site, search opens PRE-SCOPED to these — a Calico 3.32 page
72
+ * searches Calico 3.32 by default. The scope is seeded as normal facet
73
+ * selections, so the reader can untick them to search wider.
74
+ */
75
+ scopeProduct?: string;
76
+ scopeVersion?: string;
77
+ /** A crowded header: the button's "Search ⌘K" text only from 1536 px, an icon below. */
78
+ compact?: boolean;
44
79
  }
45
80
 
46
81
  const {
47
- pagefindUrl = "/pagefind/",
82
+ pagefindUrl,
83
+ pagefindBaseUrl,
84
+ navUrl,
48
85
  placeholder = "Search docs...",
49
86
  taxonomyDisplay,
87
+ scopeProduct,
88
+ scopeVersion,
89
+ compact = false,
50
90
  } = Astro.props;
51
91
  ---
52
92
 
53
93
  <dialog
54
94
  data-search-dialog
55
95
  data-pagefind-url={pagefindUrl}
96
+ data-pagefind-base-url={pagefindBaseUrl}
97
+ data-nav-url={navUrl}
56
98
  data-taxonomy-display={taxonomyDisplay ? JSON.stringify(taxonomyDisplay) : ""}
99
+ data-scope-product={scopeProduct ?? ""}
100
+ data-scope-version={scopeVersion ?? ""}
57
101
  class="fixed left-1/2 top-[10vh] z-50 w-[calc(100vw-2rem)] max-w-4xl -translate-x-1/2 rounded-xl border border-border bg-popover p-0 text-popover-foreground shadow-2xl backdrop:bg-black/40 backdrop:backdrop-blur-sm"
58
102
  >
59
103
  <form method="dialog" class="flex flex-col">
@@ -121,7 +165,7 @@ const {
121
165
  <button
122
166
  type="button"
123
167
  data-search-trigger
124
- class="inline-flex h-9 items-center gap-2 rounded-md border border-border bg-background px-3 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
168
+ class="inline-flex h-9 shrink-0 items-center gap-2 whitespace-nowrap rounded-md border border-border bg-background px-3 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
125
169
  aria-label="Open search"
126
170
  >
127
171
  <svg
@@ -139,8 +183,8 @@ const {
139
183
  <circle cx="11" cy="11" r="8" />
140
184
  <path d="m21 21-4.3-4.3" />
141
185
  </svg>
142
- <span class="hidden sm:inline">Search</span>
143
- <kbd class="hidden rounded border border-border px-1.5 py-0.5 font-mono text-[10px] sm:inline">
186
+ <span class:list={["hidden", compact ? "2xl:inline" : "sm:inline"]}>Search</span>
187
+ <kbd class:list={["hidden rounded border border-border px-1.5 py-0.5 font-mono text-[10px]", compact ? "2xl:inline" : "sm:inline"]}>
144
188
  ⌘K
145
189
  </kbd>
146
190
  </button>
@@ -156,15 +200,22 @@ const {
156
200
  shapeFacets,
157
201
  resolveFacetLabel,
158
202
  resolveFacetTitle,
203
+ sortFacetNames,
159
204
  filterStateToUrlParams,
160
205
  parseFiltersFromUrl,
161
206
  filterStateToPagefindFilters,
162
207
  toggleFilter,
163
208
  countActiveFilters,
209
+ buildFacetTree,
210
+ computeTreeState,
211
+ toggleTreeNode,
164
212
  type FacetMap,
213
+ type FacetTreeNode,
165
214
  type FilterState,
215
+ type NavLike,
166
216
  type TaxonomyDisplayMap,
167
217
  } from "./search-facets.js";
218
+ import { applyPagefindBaseUrl } from "./pagefind-base-url.js";
168
219
 
169
220
  type PagefindResult = {
170
221
  id: string;
@@ -177,15 +228,24 @@ const {
177
228
  meta: { title?: string };
178
229
  sub_results?: Array<{ title: string; url: string; excerpt: string }>;
179
230
  };
231
+ // Filter values match what filterStateToPagefindFilters emits:
232
+ // each facet wrapped in `{any: [...]}` for OR-within-facet semantics.
233
+ // Pagefind also accepts other operator shapes (`all`/`none`/`not`,
234
+ // bare strings, bare arrays) but we only emit the `any` form.
235
+ type PagefindFilterValue = { any: string[] };
180
236
  type PagefindModule = {
181
237
  search(
182
238
  query: string,
183
- options?: { filters?: Record<string, string[]> },
239
+ options?: { filters?: Record<string, PagefindFilterValue> },
184
240
  ): Promise<{ results: PagefindResult[] }>;
185
241
  filters(): Promise<Record<string, Record<string, number>>>;
242
+ options?(opts: { baseUrl?: string }): Promise<void>;
186
243
  };
187
244
 
188
245
  const dialog = document.querySelector<HTMLDialogElement>("[data-search-dialog]");
246
+ // Current page's product/version — search opens pre-scoped to these.
247
+ const scopeProduct = dialog?.dataset.scopeProduct || "";
248
+ const scopeVersion = dialog?.dataset.scopeVersion || "";
189
249
  const trigger = document.querySelector<HTMLButtonElement>("[data-search-trigger]");
190
250
  const input = dialog?.querySelector<HTMLInputElement>("[data-search-input]");
191
251
  const resultsBox = dialog?.querySelector<HTMLDivElement>("[data-search-results]");
@@ -204,6 +264,15 @@ const {
204
264
  let filters: FilterState = {};
205
265
  let availableFacets: FacetMap = {};
206
266
 
267
+ // Nav data cached after first fetch — used to derive the
268
+ // segment-encoded hierarchical-facet tree (the auto-`category`
269
+ // case). Null while pending or absent. The fetch fires lazily
270
+ // the first time renderFacets() encounters a hierarchical facet,
271
+ // not eagerly on dialog open, so sites without hierarchical
272
+ // facets never pay for it.
273
+ let navData: NavLike[] | null = null;
274
+ let loadingNav: Promise<void> | null = null;
275
+
207
276
  // Display config baked into a data attribute by the Astro
208
277
  // template — parsed lazily.
209
278
  const taxonomyDisplay: TaxonomyDisplayMap = (() => {
@@ -218,10 +287,28 @@ const {
218
287
  async function ensurePagefindLoaded() {
219
288
  if (pagefind) return;
220
289
  if (loadingPagefind) return loadingPagefind;
221
- const url = (dialog!.dataset.pagefindUrl ?? "/pagefind/") + "pagefind.js";
290
+ // pagefindUrl is required — a "/pagefind/" fallback would
291
+ // silently 404 on subpath-mounted deploys (GH Pages project
292
+ // pages, multi-mount Cloudflare). The emitter always passes
293
+ // a combined-prefix-aware value via data-pagefind-url. If it's
294
+ // missing the page wasn't built through format-astro and the
295
+ // caller forgot to pass it.
296
+ const dataUrl = dialog!.dataset.pagefindUrl;
297
+ if (!dataUrl) {
298
+ console.error(
299
+ "[dogsbay] SearchDialog: pagefindUrl prop missing. " +
300
+ "Pass the combined-prefix path (e.g. '/<base>/pagefind/') " +
301
+ "from your DocsLayout instantiation.",
302
+ );
303
+ return;
304
+ }
305
+ const url = dataUrl + "pagefind.js";
222
306
  loadingPagefind = (async () => {
223
307
  try {
224
308
  const mod = (await import(/* @vite-ignore */ url)) as PagefindModule;
309
+ // Before the first search: result URLs are built with this base.
310
+ // Without it a Workers subpath mount links to /<mount>/<mount>/page/.
311
+ await applyPagefindBaseUrl(mod, dialog!.dataset.pagefindBaseUrl);
225
312
  pagefind = mod;
226
313
  // Discover facets once, on first load. Pagefind builds
227
314
  // this from the body-level data-pagefind-filter elements.
@@ -237,6 +324,49 @@ const {
237
324
  return loadingPagefind;
238
325
  }
239
326
 
327
+ /**
328
+ * Lazy nav.json fetch, kicked off the first time a hierarchical
329
+ * facet is rendered. Mirrors the pattern in `docs-nav-client.ts` —
330
+ * one fetch per session, `same-origin` credentials so cookied
331
+ * mounts work, module-level cache.
332
+ *
333
+ * When the fetch resolves we re-call `renderFacets()` so the
334
+ * previously-flat segment-encoded facet upgrades to its tree
335
+ * shape — without this, a slow nav fetch would leave the facets
336
+ * stuck on the flat fallback until the user toggled a filter.
337
+ *
338
+ * Network errors are logged and swallowed; the helper's flat
339
+ * fallback keeps the dialog functional.
340
+ */
341
+ async function ensureNavLoaded() {
342
+ if (navData !== null) return;
343
+ if (loadingNav) return loadingNav;
344
+ const url = dialog!.dataset.navUrl;
345
+ if (!url) return; // navUrl not provided — flat fallback stays
346
+ loadingNav = (async () => {
347
+ try {
348
+ const res = await fetch(url, { credentials: "same-origin" });
349
+ if (!res.ok) throw new Error(`nav.json fetch failed: ${res.status}`);
350
+ const data = (await res.json()) as unknown;
351
+ navData = Array.isArray(data) ? (data as NavLike[]) : [];
352
+ // Re-render so hierarchical segment-encoded facets pick up
353
+ // the nav shape. Cheap — no Pagefind round-trip, just a
354
+ // DOM rebuild from `availableFacets`.
355
+ if (Object.keys(availableFacets).length > 0) {
356
+ renderFacets();
357
+ }
358
+ } catch (err) {
359
+ console.warn(
360
+ "[dogsbay] failed to load nav.json (hierarchical facets fall back to flat list):",
361
+ err,
362
+ );
363
+ // Mark as loaded-with-empty so we don't keep retrying.
364
+ navData = [];
365
+ }
366
+ })();
367
+ return loadingNav;
368
+ }
369
+
240
370
  function escapeHtml(s: string): string {
241
371
  return s
242
372
  .replace(/&/g, "&amp;")
@@ -313,54 +443,171 @@ const {
313
443
  resultsBox!.innerHTML = html;
314
444
  }
315
445
 
446
+ /**
447
+ * Hierarchical-facet caches, rebuilt on every renderFacets() so
448
+ * they stay aligned with the current filter state + available
449
+ * facets. The trees are the source for `value → node` lookups
450
+ * during click handling (parent click expands selection to all
451
+ * descendants — needs the node to know what to add).
452
+ */
453
+ const facetTrees = new Map<string, FacetTreeNode[]>();
454
+ const facetNodesByValue = new Map<string, Map<string, FacetTreeNode>>();
455
+
456
+ /**
457
+ * Decide whether a facet renders as a tree. `category` defaults
458
+ * to hierarchical (auto-derived path segments are the canonical
459
+ * use case); explicit override via `taxonomyDisplay[name].hierarchical`
460
+ * wins both ways.
461
+ */
462
+ function isHierarchicalFacet(name: string): boolean {
463
+ const flag = taxonomyDisplay[name]?.hierarchical;
464
+ if (typeof flag === "boolean") return flag;
465
+ return name === "category";
466
+ }
467
+
468
+ /**
469
+ * Flatten a tree into a `value → node` map so the click handler
470
+ * can look up the clicked node without re-walking the tree.
471
+ */
472
+ function indexTree(nodes: FacetTreeNode[]): Map<string, FacetTreeNode> {
473
+ const out = new Map<string, FacetTreeNode>();
474
+ const visit = (n: FacetTreeNode): void => {
475
+ out.set(n.value, n);
476
+ for (const c of n.children) visit(c);
477
+ };
478
+ for (const r of nodes) visit(r);
479
+ return out;
480
+ }
481
+
482
+ /**
483
+ * Recursive HTML for one tree node. Synthetic parents (`hasValue:
484
+ * false`) render as a clickable group header — checking them
485
+ * still cascades to descendants via toggleTreeNode. Indent scales
486
+ * with `node.depth`.
487
+ */
488
+ function renderTreeNode(name: string, node: FacetTreeNode): string {
489
+ const state = computeTreeState(node, name, filters);
490
+ const id = `facet-${name}-${node.value}`.replace(/[^a-z0-9-]/gi, "-");
491
+ const indent = node.depth * 12;
492
+ const label = escapeHtml(node.label);
493
+ const countText = node.hasValue ? `${node.count}` : "";
494
+ const stateAttr =
495
+ state === "checked" ? "checked" : state === "indeterminate" ? 'data-tree-indeterminate="true"' : "";
496
+ const childrenHtml = node.children
497
+ .map((c) => renderTreeNode(name, c))
498
+ .join("");
499
+ return `
500
+ <li>
501
+ <label
502
+ for="${id}"
503
+ class="flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 hover:bg-accent"
504
+ style="padding-left: ${0.5 + indent / 16}rem"
505
+ >
506
+ <input
507
+ type="checkbox"
508
+ id="${id}"
509
+ data-facet-name="${escapeHtml(name)}"
510
+ data-facet-value="${escapeHtml(node.value)}"
511
+ data-tree-node="true"
512
+ ${state === "checked" ? "checked" : ""}
513
+ ${state === "indeterminate" ? 'data-tree-indeterminate="true"' : ""}
514
+ class="size-3.5 rounded border-border accent-primary"
515
+ />
516
+ <span class="flex-1 truncate">${label}</span>
517
+ <span class="text-xs text-muted-foreground">${countText}</span>
518
+ </label>
519
+ ${childrenHtml ? `<ul class="space-y-0.5">${childrenHtml}</ul>` : ""}
520
+ </li>
521
+ `;
522
+ }
523
+
316
524
  /**
317
525
  * Build the facets sidebar. Runs once after Pagefind discovers
318
526
  * filters, then again whenever filter state changes (so checkbox
319
527
  * `checked` reflects current selections). When the corpus has no
320
528
  * filters, the sidebar stays hidden — single-column layout.
529
+ *
530
+ * Branches per facet: hierarchical taxonomies (and the built-in
531
+ * `category` default) render as a tree; flat taxonomies keep the
532
+ * original checkbox-list shape. The hierarchical path falls back
533
+ * to a flat list automatically when segment-encoded values lack a
534
+ * `nav` source — preserves render-ability until Phase 3 wires the
535
+ * nav.json fetch.
321
536
  */
322
537
  function renderFacets() {
323
- const facetNames = Object.keys(availableFacets);
538
+ const facetNames = sortFacetNames(
539
+ Object.keys(availableFacets),
540
+ taxonomyDisplay,
541
+ );
324
542
  if (facetNames.length === 0) {
325
543
  facetsBox!.classList.add("hidden");
326
544
  return;
327
545
  }
328
546
  facetsBox!.classList.remove("hidden");
329
547
 
548
+ facetTrees.clear();
549
+ facetNodesByValue.clear();
550
+
330
551
  const activeCount = countActiveFilters(filters);
331
552
  const clearAll = activeCount > 0
332
553
  ? `<button type="button" data-clear-filters class="mb-3 w-full rounded-md border border-border px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground">Clear all (${activeCount})</button>`
333
554
  : "";
334
555
 
556
+ let needsNav = false;
335
557
  const groups = facetNames
336
558
  .map((name) => {
337
559
  const entries = availableFacets[name];
338
560
  const title = escapeHtml(resolveFacetTitle(name));
339
- const items = entries
340
- .map((entry) => {
341
- const checked = (filters[name] ?? []).includes(entry.value);
342
- const label = escapeHtml(
343
- resolveFacetLabel(name, entry.value, taxonomyDisplay),
344
- );
345
- const id = `facet-${name}-${entry.value}`.replace(/[^a-z0-9-]/gi, "-");
346
- return `
347
- <li>
348
- <label for="${id}" class="flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 hover:bg-accent">
349
- <input
350
- type="checkbox"
351
- id="${id}"
352
- data-facet-name="${escapeHtml(name)}"
353
- data-facet-value="${escapeHtml(entry.value)}"
354
- ${checked ? "checked" : ""}
355
- class="size-3.5 rounded border-border accent-primary"
356
- />
357
- <span class="flex-1 truncate">${label}</span>
358
- <span class="text-xs text-muted-foreground">${entry.count}</span>
359
- </label>
360
- </li>
361
- `;
362
- })
363
- .join("");
561
+ const hierarchical = isHierarchicalFacet(name);
562
+
563
+ let items: string;
564
+ if (hierarchical) {
565
+ // Every hierarchical facet wants nav.json — slash-encoded
566
+ // for sort order at each depth (so docs follow nav rather
567
+ // than count-desc), segment-encoded for the tree structure
568
+ // itself. Without nav, slash-encoded still renders a tree
569
+ // (using values alone) but in count-desc order, which is
570
+ // wrong on corpora where one branch dwarfs the rest
571
+ // (openshift's rest_api section). Fire ensureNavLoaded()
572
+ // any time a hierarchical facet renders with navData still
573
+ // null — when it resolves, renderFacets re-runs and
574
+ // upgrades the sort.
575
+ if (navData === null) needsNav = true;
576
+ const tree = buildFacetTree(name, entries, {
577
+ display: taxonomyDisplay,
578
+ nav: navData ?? undefined,
579
+ });
580
+ facetTrees.set(name, tree);
581
+ facetNodesByValue.set(name, indexTree(tree));
582
+ items = tree.map((n) => renderTreeNode(name, n)).join("");
583
+ } else {
584
+ items = entries
585
+ .map((entry) => {
586
+ const checked = (filters[name] ?? []).includes(entry.value);
587
+ const label = escapeHtml(
588
+ resolveFacetLabel(name, entry.value, taxonomyDisplay),
589
+ );
590
+ const id = `facet-${name}-${entry.value}`.replace(/[^a-z0-9-]/gi, "-");
591
+ return `
592
+ <li>
593
+ <label for="${id}" class="flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 hover:bg-accent">
594
+ <input
595
+ type="checkbox"
596
+ id="${id}"
597
+ data-facet-name="${escapeHtml(name)}"
598
+ data-facet-value="${escapeHtml(entry.value)}"
599
+ ${checked ? "checked" : ""}
600
+ class="size-3.5 rounded border-border accent-primary"
601
+ />
602
+ <span class="flex-1 truncate">${label}</span>
603
+ <span class="text-xs text-muted-foreground">${entry.count}</span>
604
+ </label>
605
+ </li>
606
+ `;
607
+ })
608
+ .join("");
609
+ }
610
+
364
611
  return `
365
612
  <fieldset class="mb-3">
366
613
  <legend class="mb-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground">${title}</legend>
@@ -371,6 +618,20 @@ const {
371
618
  .join("");
372
619
 
373
620
  facetsBox!.innerHTML = clearAll + groups;
621
+
622
+ // `indeterminate` is a JS property, not an HTML attribute —
623
+ // can't set via innerHTML. Walk new checkboxes and set it
624
+ // post-paint so the visual tri-state matches state.
625
+ const indet = facetsBox!.querySelectorAll<HTMLInputElement>(
626
+ 'input[type="checkbox"][data-tree-indeterminate="true"]',
627
+ );
628
+ for (const el of Array.from(indet)) el.indeterminate = true;
629
+
630
+ // Lazy nav fetch — fired only when at least one hierarchical
631
+ // segment-encoded facet rendered with the flat fallback. The
632
+ // fetch's resolution handler calls renderFacets() again so the
633
+ // facet upgrades to its real tree shape without user action.
634
+ if (needsNav) void ensureNavLoaded();
374
635
  }
375
636
 
376
637
  async function runSearch(query: string) {
@@ -425,9 +686,22 @@ const {
425
686
  const fromUrl = parseFiltersFromUrl(new URLSearchParams(window.location.search));
426
687
  input!.value = fromUrl.query;
427
688
  filters = fromUrl.filters;
689
+ const hadUrlState = fromUrl.query.length > 0 || countActiveFilters(filters) > 0;
690
+ // Auto-scope: a FRESH open (no filters/query carried in the URL) on a
691
+ // multi-product/versioned site starts scoped to the CURRENT product +
692
+ // version. Seeded as ordinary facet selections, so the reader can
693
+ // untick "Product: calico" / "Version: 3.32" to search wider. A URL
694
+ // that already carries state wins (shared/roundtripped searches).
695
+ if (!hadUrlState) {
696
+ if (scopeProduct) filters.product = [scopeProduct];
697
+ if (scopeVersion) filters.version = [scopeVersion];
698
+ }
428
699
  renderFacets();
429
700
 
430
- const hasInitial = input!.value.length > 0 || countActiveFilters(filters) > 0;
701
+ // Run immediately only when there's a query or the state came from the
702
+ // URL. A fresh open shows the empty prompt with the scope pre-ticked —
703
+ // results appear (scoped) as soon as the reader types.
704
+ const hasInitial = hadUrlState;
431
705
  if (hasInitial) {
432
706
  runSearch(input!.value);
433
707
  } else {
@@ -475,13 +749,26 @@ const {
475
749
  });
476
750
 
477
751
  // Facet checkbox toggling — event delegation on the sidebar.
752
+ // Tree nodes route through toggleTreeNode (parent click expands
753
+ // to all descendants); flat checkboxes use toggleFilter as before.
754
+ // We compute state from the pre-click filter, NOT from the
755
+ // checkbox's post-click `checked` value — the browser has already
756
+ // flipped it by the time `change` fires, so reading it would
757
+ // invert our toggle direction for indeterminate parents.
478
758
  facetsBox.addEventListener("change", (e) => {
479
759
  const target = e.target as HTMLInputElement;
480
760
  if (target.tagName !== "INPUT" || target.type !== "checkbox") return;
481
761
  const name = target.dataset.facetName;
482
762
  const value = target.dataset.facetValue;
483
763
  if (!name || !value) return;
484
- filters = toggleFilter(filters, name, value);
764
+ if (target.dataset.treeNode === "true") {
765
+ const node = facetNodesByValue.get(name)?.get(value);
766
+ if (!node) return;
767
+ const currentState = computeTreeState(node, name, filters);
768
+ filters = toggleTreeNode(filters, name, node, currentState);
769
+ } else {
770
+ filters = toggleFilter(filters, name, value);
771
+ }
485
772
  renderFacets();
486
773
  runSearch(input!.value);
487
774
  syncUrl();
@@ -0,0 +1,34 @@
1
+ ---
2
+ /**
3
+ * Brand icon links (`header.social`, `footer.social`; `site.repoUrl` is the header's default).
4
+ * The SVG is @dogsbay/icons' (aria-hidden); the link carries the name. Another site opens in a
5
+ * new tab, as the repository icon always did.
6
+ */
7
+ import { isExternal, type SiteChromeSocial } from "./site-chrome.js";
8
+
9
+ interface Props {
10
+ links: SiteChromeSocial[];
11
+ size?: "header" | "footer";
12
+ /** Classes for each link (the header hides them below md, where they are in the sidebar). */
13
+ class?: string;
14
+ }
15
+ const { links, size = "header", class: className } = Astro.props;
16
+ ---
17
+
18
+ {links.map((s) => (
19
+ <a
20
+ href={s.href}
21
+ target={isExternal(s.href) ? "_blank" : undefined}
22
+ rel={isExternal(s.href) ? "noopener" : undefined}
23
+ aria-label={s.label}
24
+ title={s.label}
25
+ class:list={[
26
+ "inline-flex items-center justify-center text-muted-foreground hover:text-foreground",
27
+ size === "header" ? "rounded-md p-2 hover:bg-accent" : "p-1",
28
+ className,
29
+ ]}
30
+ data-social-link
31
+ >
32
+ <Fragment set:html={s.svg} />
33
+ </a>
34
+ ))}
package/src/TagList.astro CHANGED
@@ -48,6 +48,11 @@ interface Props {
48
48
  * text. URL still uses the slug.
49
49
  */
50
50
  labels?: Record<string, string>;
51
+ /**
52
+ * Give chips whose prefix has no color a stable palette color,
53
+ * hashed from the tag's first segment. Default false.
54
+ */
55
+ autoColor?: boolean;
51
56
  /** Optional aria-label override; default "Tags". */
52
57
  label?: string;
53
58
  class?: string;
@@ -58,11 +63,12 @@ const {
58
63
  indexPath = "/tags",
59
64
  prefixes,
60
65
  labels,
66
+ autoColor = false,
61
67
  label: ariaLabel = "Tags",
62
68
  class: className,
63
69
  } = Astro.props;
64
70
 
65
- const chips = buildChips(tags, { indexPath, prefixes, labels });
71
+ const chips = buildChips(tags, { indexPath, prefixes, labels, autoColor });
66
72
 
67
73
  /**
68
74
  * Closed palette → Tailwind class strings. Each entry is one
@@ -72,8 +78,13 @@ const chips = buildChips(tags, { indexPath, prefixes, labels });
72
78
  */
73
79
  const PALETTE: Record<TagPaletteName, string> = {
74
80
  blue: "border-blue-500/40 bg-blue-500/15 text-blue-700 dark:text-blue-300",
81
+ // amber-800, not -700, in light mode: amber-700 on amber-500/15 is
82
+ // 4.48:1 — under 4.5:1 by a hair, and failing regardless of the
83
+ // opacity bug below. -800 gives 6.32:1. Every other colour clears it
84
+ // at -700 (4.76–8.60:1). Dark mode is unaffected: text-*-300 on the
85
+ // same tint over a dark page is 9–12:1 across the palette.
75
86
  amber:
76
- "border-amber-500/40 bg-amber-500/15 text-amber-700 dark:text-amber-300",
87
+ "border-amber-500/40 bg-amber-500/15 text-amber-800 dark:text-amber-300",
77
88
  emerald:
78
89
  "border-emerald-500/40 bg-emerald-500/15 text-emerald-700 dark:text-emerald-300",
79
90
  violet:
@@ -108,7 +119,17 @@ const DEFAULT_CLASS =
108
119
  >
109
120
  {chip.prefixLabel ? (
110
121
  <Fragment>
111
- <span class="opacity-70">{chip.prefixLabel}:</span>
122
+ {/*
123
+ No opacity here. `opacity-70` on the prefix blended the
124
+ text 30% toward the chip background and put EVERY colour
125
+ in the palette below 4.5:1 — measured 2.75–3.95:1, worst
126
+ amber, best slate. It is 12px text, so 4.5:1 applies.
127
+
128
+ The prefix/leaf distinction is carried by font-weight
129
+ instead: the leaf below is font-semibold against the
130
+ anchor's font-medium. Weight costs no contrast.
131
+ */}
132
+ <span>{chip.prefixLabel}:</span>
112
133
  <span class="font-semibold">{chip.leafLabel}</span>
113
134
  </Fragment>
114
135
  ) : (