@dogsbay/docs-layout 0.2.0-beta.150 → 0.2.0-beta.152

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dogsbay/docs-layout",
3
- "version": "0.2.0-beta.150",
3
+ "version": "0.2.0-beta.152",
4
4
  "description": "Standard documentation layout components for Dogsbay",
5
5
  "type": "module",
6
6
  "exports": {
@@ -35,10 +35,11 @@
35
35
  "./site-chrome": "./src/site-chrome.ts"
36
36
  },
37
37
  "dependencies": {
38
- "@dogsbay/elements": "0.2.0-beta.150",
39
- "@dogsbay/primitives": "0.2.0-beta.150",
40
- "@dogsbay/ui": "0.2.0-beta.150",
41
- "@dogsbay/site-files": "0.2.0-beta.150"
38
+ "@dogsbay/elements": "0.2.0-beta.152",
39
+ "@dogsbay/primitives": "0.2.0-beta.152",
40
+ "@dogsbay/search": "0.2.0-beta.152",
41
+ "@dogsbay/site-files": "0.2.0-beta.152",
42
+ "@dogsbay/ui": "0.2.0-beta.152"
42
43
  },
43
44
  "devDependencies": {
44
45
  "happy-dom": "^20.10.6",
@@ -8,14 +8,14 @@
8
8
  import { ANNOUNCEMENT_TONE_CLASS } from "./site-chrome.js";
9
9
 
10
10
  interface Props {
11
- announcement: { id: string; html: string; tone: string; closeable: boolean };
11
+ announcement: { id: string; key?: string; html: string; tone: string; closeable: boolean };
12
12
  }
13
13
  const { announcement } = Astro.props;
14
14
  const tone = ANNOUNCEMENT_TONE_CLASS[announcement.tone] ?? ANNOUNCEMENT_TONE_CLASS.note;
15
15
  ---
16
16
 
17
17
  <db-announcement
18
- announcement-id={announcement.id}
18
+ announcement-id={announcement.key ?? announcement.id}
19
19
  class:list={["db-announcement block border-b text-sm text-foreground", tone]}
20
20
  role="region"
21
21
  aria-label="Announcement"
@@ -48,7 +48,7 @@ import ProductSwitcher from "./ProductSwitcher.astro";
48
48
  import AnnouncementBar from "./AnnouncementBar.astro";
49
49
  import HeaderLinks from "./HeaderLinks.astro";
50
50
  import SocialLinks from "./SocialLinks.astro";
51
- import type { SiteChromeData } from "./site-chrome.js";
51
+ import { headerLinksFrom, type LinksFrom, type SiteChromeData } from "./site-chrome.js";
52
52
  import { COLOR_MODE_HEAD_SCRIPTS } from "@dogsbay/elements/color-mode-head";
53
53
  import { ANNOUNCEMENT_CSS, ANNOUNCEMENT_HEAD_SCRIPT } from "@dogsbay/elements/announcement-head";
54
54
  import LocaleSwitcher from "./LocaleSwitcher.astro";
@@ -619,6 +619,14 @@ const showLlmActionsInline =
619
619
  llmActionsEnabled
620
620
  && (llmActionsPlacement === "inline" || llmActionsPlacement === "both");
621
621
  const llmFooterLink = !!llmActions && llmActions.footerLink !== false;
622
+ // A header holding links AND the menus (product, version, page actions) is crowded: search and
623
+ // the page actions are icons below 2xl, and below lg the menus wrap to as many rows as they need
624
+ // (the header grows; data-header on <html> sets the height headings jump below). The links sit in
625
+ // the bar from the first width they fit at (headerLinksFrom), in the sidebar below it. Tigera's
626
+ // header needed it: 1280 px broke labels, 390 px scrolled sideways.
627
+ const headerCrowded = chrome === "docs" && !!siteChrome?.header?.links.length && (!!switcherMap || showLlmActionsHeader);
628
+ const linksFrom: LinksFrom = siteChrome?.header?.links.length ? headerLinksFrom(siteChrome.header.links, headerCrowded) : "lg";
629
+ const LINKS_LIST_HIDDEN: Record<LinksFrom, string> = { lg: "lg:hidden", xl: "xl:hidden", "2xl": "2xl:hidden", never: "" };
622
630
  // Per-mount llms.txt URL — Dogsbay emits `<basePath>/llms.txt`
623
631
  // (sitemap-index pattern), so the footer link must be basePath-
624
632
  // prefixed too. Falls back to `/llms.txt` when basePath is empty
@@ -805,8 +813,9 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
805
813
  ---
806
814
 
807
815
  <!doctype html>
808
- <html lang="en">
816
+ <html lang="en" class:list={[siteChrome?.colorMode === "dark" && "dark"]} data-header={headerCrowded ? "crowded" : undefined}>
809
817
  <head>
818
+ {/* colorMode: dark is in the built page (the html class), so it holds with no script (a sandboxed preview); the head script still honours a stored "light" */}
810
819
  <meta charset="UTF-8" />
811
820
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
812
821
  <title>{title} | {siteName}</title>
@@ -820,6 +829,19 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
820
829
  :root {
821
830
  --db-header-height: 3rem;
822
831
  }
832
+ /*
833
+ A crowded header (links + menus) wraps its menus below 1024 px and grows with them, usually
834
+ to two rows: the variable is that estimate, for what offsets by it, and a heading jumped to
835
+ lands below it (a third row, with a language menu too, can still cover it).
836
+ */
837
+ @media (max-width: 63.99rem) {
838
+ :root[data-header="crowded"] {
839
+ --db-header-height: 5.25rem;
840
+ }
841
+ :root[data-header="crowded"] :is(h1, h2, h3, h4, h5, h6)[id] {
842
+ scroll-margin-top: calc(var(--db-header-height) + 1rem);
843
+ }
844
+ }
823
845
 
824
846
  /*
825
847
  Diagrams drawn by Pele (`content.diagrams: pele`, plans/pele-diagrams.md).
@@ -1054,7 +1076,7 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
1054
1076
  */}
1055
1077
  {siteChrome?.announcement?.closeable && (
1056
1078
  <>
1057
- <meta name="db-announcement" content={siteChrome.announcement.id} />
1079
+ <meta name="db-announcement" content={siteChrome.announcement.key ?? siteChrome.announcement.id} />
1058
1080
  <script is:inline set:html={ANNOUNCEMENT_HEAD_SCRIPT} />
1059
1081
  <style is:inline set:html={ANNOUNCEMENT_CSS} />
1060
1082
  </>
@@ -1085,8 +1107,8 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
1085
1107
  {siteChrome?.logo ? (
1086
1108
  <>
1087
1109
  {/* Two images, one hidden by the theme class: no script, no flash */}
1088
- <img src={siteChrome.logo.light} alt={siteChrome.logo.replacesName ? siteName : ""} class:list={["site-logo h-8 w-auto max-w-[10rem] object-contain object-left", siteChrome.logo.dark && "dark:hidden"]} />
1089
- {siteChrome.logo.dark && <img src={siteChrome.logo.dark} alt={siteChrome.logo.replacesName ? siteName : ""} class="site-logo hidden h-8 w-auto max-w-[10rem] object-contain object-left dark:block" />}
1110
+ <img src={siteChrome.logo.light} alt={siteChrome.logo.replacesName ? siteChrome.logo.alt || siteName : ""} class:list={["site-logo h-8 w-auto max-w-[10rem] object-contain object-left", siteChrome.logo.dark && "dark:hidden"]} />
1111
+ {siteChrome.logo.dark && <img src={siteChrome.logo.dark} alt={siteChrome.logo.replacesName ? siteChrome.logo.alt || siteName : ""} class="site-logo hidden h-8 w-auto max-w-[10rem] object-contain object-left dark:block" />}
1090
1112
  </>
1091
1113
  ) : (
1092
1114
  <div class="flex aspect-square size-8 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground">
@@ -1110,7 +1132,7 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
1110
1132
  <SidebarContent>
1111
1133
  {/* The header's links move here below lg, as Docusaurus moves navbar items into its drawer */}
1112
1134
  {siteChrome?.header?.links.length ? (
1113
- <SidebarGroup class="lg:hidden">
1135
+ <SidebarGroup class={LINKS_LIST_HIDDEN[linksFrom] || undefined}>
1114
1136
  <SidebarGroupContent>
1115
1137
  <HeaderLinks links={siteChrome.header.links} layout="list" currentPath={currentPath} />
1116
1138
  {/* The header's icons too, below md, where the header has no room for them beside the links */}
@@ -1190,13 +1212,16 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
1190
1212
  can never leave another sticky bar overlapping or floating.
1191
1213
  */}
1192
1214
  {siteChrome?.announcement && <AnnouncementBar announcement={siteChrome.announcement} />}
1193
- <header class="sticky top-0 z-40 flex h-[var(--db-header-height)] shrink-0 items-center gap-2 border-b bg-background/95 px-4 backdrop-blur-sm supports-[backdrop-filter]:bg-background/60">
1215
+ <header class:list={["sticky top-0 z-40 flex shrink-0 items-center gap-2 border-b bg-background/95 px-4 backdrop-blur-sm supports-[backdrop-filter]:bg-background/60", chrome !== "docs" && siteChrome?.header?.links.length ? "min-h-[var(--db-header-height)] flex-wrap py-1" : headerCrowded ? "h-[var(--db-header-height)] max-lg:h-auto max-lg:min-h-12 max-lg:py-1" : "h-[var(--db-header-height)]"]}>
1194
1216
  {chrome === "docs" && <SidebarTrigger class="-ml-1" />}
1195
1217
  <Separator orientation="vertical" class="mr-2 h-4" />
1196
- {/* With header links, the page title shows only below lg, where the links are in the sidebar */}
1197
- <span class:list={["text-sm text-muted-foreground", siteChrome?.header?.links.length && "lg:hidden"]} data-page-title>{title}</span>
1198
- {siteChrome?.header?.links.length ? <HeaderLinks links={siteChrome.header.links} currentPath={currentPath} /> : null}
1199
- <div class="ml-auto flex items-center gap-2">
1218
+ {/* With header links, the page title shows only below lg, where the links are in the sidebar;
1219
+ a layout with no sidebar keeps the links in the header (wrapping) and no title */}
1220
+ {!(chrome !== "docs" && siteChrome?.header?.links.length) && (
1221
+ <span class:list={["min-w-0 truncate text-sm text-muted-foreground", siteChrome?.header?.links.length && LINKS_LIST_HIDDEN[linksFrom], headerCrowded && "max-lg:hidden"]} data-page-title>{title}</span>
1222
+ )}
1223
+ {siteChrome?.header?.links.length ? <HeaderLinks links={siteChrome.header.links} currentPath={currentPath} wrap={chrome !== "docs"} from={linksFrom} /> : null}
1224
+ <div class:list={["ml-auto flex min-w-0 items-center gap-2", headerCrowded && "max-lg:flex-wrap max-lg:justify-end max-lg:gap-y-1"]}>
1200
1225
  <slot name="header" />
1201
1226
  {tocPlacement.popoverToc && (
1202
1227
  <details class="dba-toc-popover relative" data-toc-popover>
@@ -1231,6 +1256,7 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
1231
1256
  providers={llmActions!.providers}
1232
1257
  copyButton={llmActions!.copyButton}
1233
1258
  promptTemplate={llmActions!.promptTemplate}
1259
+ compact={headerCrowded}
1234
1260
  />
1235
1261
  )}
1236
1262
  {!hideSearch && (
@@ -1241,11 +1267,12 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
1241
1267
  taxonomyDisplay={taxonomyDisplay}
1242
1268
  scopeProduct={multiSource?.namespace}
1243
1269
  scopeVersion={multiSource?.version}
1270
+ compact={headerCrowded}
1244
1271
  />
1245
1272
  )}
1246
1273
  {siteChrome?.header ? (
1247
- <SocialLinks links={siteChrome.header.social} class={siteChrome.header.links.length ? "max-md:hidden" : undefined} />
1248
- ) : repoUrl && (
1274
+ <SocialLinks links={siteChrome.header.social} class={chrome === "docs" && siteChrome.header.links.length ? "max-md:hidden" : undefined} />
1275
+ ) : repoUrl && /^https?:\/\//i.test(repoUrl) && (
1249
1276
  <a href={repoUrl} target="_blank" rel="noopener" class="rounded-md p-2 text-muted-foreground hover:bg-accent hover:text-foreground" aria-label="Source repository">
1250
1277
  <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/></svg>
1251
1278
  </a>
@@ -2,16 +2,20 @@
2
2
  /**
3
3
  * The header's links (`header.links`): links, and one-level dropdowns as `<details>` lists like
4
4
  * the version and product menus, so every link is in the HTML (crawlers, readers without
5
- * JavaScript). `layout="bar"` for the header (from `lg`), `layout="list"` for the sidebar below it.
5
+ * JavaScript). `layout="bar"` for the header (from `lg`, or `xl`), `layout="list"` for the sidebar below it.
6
6
  */
7
- import { isExternal, isMenu, type SiteChromeLink, type SiteChromeMenu } from "./site-chrome.js";
7
+ import { isExternal, isMenu, type LinksFrom, type SiteChromeLink, type SiteChromeMenu } from "./site-chrome.js";
8
8
 
9
9
  interface Props {
10
10
  links: Array<SiteChromeLink | SiteChromeMenu>;
11
11
  layout?: "bar" | "list";
12
12
  currentPath?: string;
13
+ /** A layout with no sidebar to move them into: shown at every width, wrapping. */
14
+ wrap?: boolean;
15
+ /** The width the bar shows from (the sidebar's list below it); `never`: the sidebar's list only. */
16
+ from?: LinksFrom;
13
17
  }
14
- const { links, layout = "bar", currentPath } = Astro.props;
18
+ const { links, layout = "bar", currentPath, wrap = false, from = "lg" } = Astro.props;
15
19
  // The page, or a page under the link's section; a link to the site's root only on the root itself
16
20
  const current = (href: string) => {
17
21
  if (!currentPath || isExternal(href)) return undefined;
@@ -23,11 +27,11 @@ const current = (href: string) => {
23
27
  ---
24
28
 
25
29
  {layout === "bar" ? (
26
- <nav aria-label="Site" class="site-header-links hidden items-center gap-1 lg:flex">
30
+ <nav aria-label="Site" class:list={["site-header-links items-center gap-1", wrap ? "flex min-w-0 flex-wrap" : { lg: "hidden lg:flex", xl: "hidden xl:flex", "2xl": "hidden 2xl:flex", never: "hidden" }[from]]}>
27
31
  {links.map((l) =>
28
32
  isMenu(l) ? (
29
33
  <details class="site-header-menu relative">
30
- <summary class="flex cursor-pointer items-center gap-1 rounded-md px-2 py-1.5 text-sm text-muted-foreground hover:bg-accent hover:text-foreground">
34
+ <summary class="flex cursor-pointer items-center gap-1 whitespace-nowrap rounded-md px-2 py-1.5 text-sm text-muted-foreground hover:bg-accent hover:text-foreground">
31
35
  {l.label}
32
36
  <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="6 9 12 15 18 9"/></svg>
33
37
  </summary>
@@ -38,7 +42,7 @@ const current = (href: string) => {
38
42
  </ul>
39
43
  </details>
40
44
  ) : (
41
- <a href={l.href} aria-current={current(l.href)} class="rounded-md px-2 py-1.5 text-sm text-muted-foreground no-underline hover:bg-accent hover:text-foreground aria-[current=page]:text-foreground">{l.label}</a>
45
+ <a href={l.href} aria-current={current(l.href)} class="whitespace-nowrap rounded-md px-2 py-1.5 text-sm text-muted-foreground no-underline hover:bg-accent hover:text-foreground aria-[current=page]:text-foreground">{l.label}</a>
42
46
  ),
43
47
  )}
44
48
  </nav>
@@ -35,11 +35,11 @@ const currentLabel = currentRow?.entry.label ?? currentRow?.entry.id ?? "Locale"
35
35
  {visible && (
36
36
  <details class="locale-switcher relative">
37
37
  <summary
38
- class="flex cursor-pointer items-center gap-1 rounded-md border border-border px-3 py-1.5 text-sm hover:bg-accent"
38
+ class="flex cursor-pointer items-center gap-1 whitespace-nowrap rounded-md border border-border px-3 py-1.5 text-sm hover:bg-accent max-md:px-2"
39
39
  aria-label="Switch language"
40
40
  >
41
41
  <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><path d="M2 12h20"/><path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/></svg>
42
- <span class="font-medium">{currentLabel}</span>
42
+ <span class="max-w-[10rem] truncate font-medium max-md:max-w-[6rem]">{currentLabel}</span>
43
43
  <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="ml-1 transition-transform"><polyline points="6 9 12 15 18 9"/></svg>
44
44
  </summary>
45
45
  <ul class="absolute right-0 z-50 mt-1 min-w-[10rem] rounded-md border border-border bg-popover p-1 text-sm shadow-md">
@@ -68,6 +68,8 @@ interface Props {
68
68
  promptTemplate?: string;
69
69
  /** Optional class for layout-side styling. */
70
70
  class?: string;
71
+ /** A crowded header: below 2xl the button is an icon (its aria-label names it). */
72
+ compact?: boolean;
71
73
  }
72
74
 
73
75
  const {
@@ -77,6 +79,7 @@ const {
77
79
  copyButton = true,
78
80
  promptTemplate = DEFAULT_PROMPT_TEMPLATE,
79
81
  class: className,
82
+ compact = false,
80
83
  } = Astro.props;
81
84
 
82
85
  const resolvedProviders = resolveProviders(providers);
@@ -101,10 +104,13 @@ const itemClass =
101
104
  >
102
105
  <DropdownMenu>
103
106
  <DropdownMenuTrigger
104
- class="inline-flex h-8 items-center gap-1 rounded-md border border-border bg-background px-3 text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
107
+ class={["inline-flex h-8 shrink-0 items-center gap-1 whitespace-nowrap rounded-md border border-border bg-background text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", compact ? "px-3 max-2xl:px-2" : "px-3"].join(" ")}
105
108
  aria-label="Copy or open page actions"
106
109
  >
107
- <span>Copy or open</span>
110
+ {compact && (
111
+ <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="2xl:hidden"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>
112
+ )}
113
+ <span class:list={[compact && "max-2xl:hidden"]}>Copy or open</span>
108
114
  <svg
109
115
  xmlns="http://www.w3.org/2000/svg"
110
116
  width="14"
@@ -23,9 +23,9 @@ const menu = productMenu(switcherMap, multiSource);
23
23
 
24
24
  {menu && (
25
25
  <details class="product-switcher relative" data-product-switcher>
26
- <summary class="flex cursor-pointer items-center gap-1 rounded-md border border-border px-3 py-1.5 text-sm hover:bg-accent">
26
+ <summary class="flex cursor-pointer items-center gap-1 whitespace-nowrap rounded-md border border-border px-3 py-1.5 text-sm hover:bg-accent max-md:px-2">
27
27
  {menu.current && <span class="sr-only">{placeholder}: </span>}
28
- <span class:list={["font-medium", !menu.current && "text-muted-foreground"]}>{menu.current?.label ?? placeholder}</span>
28
+ <span class:list={["max-w-[12rem] truncate font-medium max-md:max-w-[7rem]", !menu.current && "text-muted-foreground"]}>{menu.current?.label ?? placeholder}</span>
29
29
  <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="ml-1 transition-transform" aria-hidden="true"><polyline points="6 9 12 15 18 9"/></svg>
30
30
  </summary>
31
31
  <ul class="absolute right-0 z-50 mt-1 min-w-[10rem] rounded-md border border-border bg-popover p-1 text-sm shadow-md">
@@ -74,6 +74,8 @@ interface Props {
74
74
  */
75
75
  scopeProduct?: string;
76
76
  scopeVersion?: string;
77
+ /** A crowded header: the button's "Search ⌘K" text only from 1536 px, an icon below. */
78
+ compact?: boolean;
77
79
  }
78
80
 
79
81
  const {
@@ -84,6 +86,7 @@ const {
84
86
  taxonomyDisplay,
85
87
  scopeProduct,
86
88
  scopeVersion,
89
+ compact = false,
87
90
  } = Astro.props;
88
91
  ---
89
92
 
@@ -162,7 +165,7 @@ const {
162
165
  <button
163
166
  type="button"
164
167
  data-search-trigger
165
- 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"
166
169
  aria-label="Open search"
167
170
  >
168
171
  <svg
@@ -180,8 +183,8 @@ const {
180
183
  <circle cx="11" cy="11" r="8" />
181
184
  <path d="m21 21-4.3-4.3" />
182
185
  </svg>
183
- <span class="hidden sm:inline">Search</span>
184
- <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"]}>
185
188
  ⌘K
186
189
  </kbd>
187
190
  </button>
@@ -38,8 +38,8 @@ const currentLabel = currentRow?.entry.label ?? currentRow?.entry.id ?? "Version
38
38
 
39
39
  {visible && (
40
40
  <details class="version-switcher relative">
41
- <summary class="flex cursor-pointer items-center gap-1 rounded-md border border-border px-3 py-1.5 text-sm hover:bg-accent">
42
- <span class="font-medium">{currentLabel}</span>
41
+ <summary class="flex cursor-pointer items-center gap-1 whitespace-nowrap rounded-md border border-border px-3 py-1.5 text-sm hover:bg-accent max-md:px-2">
42
+ <span class="max-w-[10rem] truncate font-medium max-md:max-w-[6rem]">{currentLabel}</span>
43
43
  {currentRow?.entry.eol && (
44
44
  <span class="ml-1 rounded bg-muted px-1 text-[10px] uppercase text-muted-foreground">EOL</span>
45
45
  )}
@@ -1,67 +1,16 @@
1
1
  /**
2
- * Pure helpers for search-facet UI in `<SearchDialog>`. Splitting
3
- * the data transforms here lets vitest exercise them without
4
- * needing a Pagefind runtime or rendered DOM.
2
+ * Search-facet helpers for `<SearchDialog>`. The pure helpers (shaping,
3
+ * labels, order, trees, URL state) live in `@dogsbay/search/facets`,
4
+ * shared with dogsbay-ssg; only the Pagefind mapping is here.
5
5
  *
6
6
  * See plans/search-facets.md.
7
7
  */
8
- import { resolveTermLabel } from "./tag-list-data.js";
9
- import type { PrefixDisplay } from "./tag-list-data.js";
10
-
11
- /**
12
- * Per-taxonomy display config — same shape as
13
- * `SiteConfig.taxonomyDisplay[name]`. Keyed locally so this module
14
- * has no runtime dependency on `@dogsbay/types`.
15
- */
16
- export interface TaxonomyDisplay {
17
- prefixes?: Record<string, PrefixDisplay>;
18
- labels?: Record<string, string>;
19
- /**
20
- * Sort weight for the facet column in the search dialog. Lower
21
- * numbers appear first. Facets without an `order` sort
22
- * alphabetically *after* any pinned ones — so `{ type: { order: 1 } }`
23
- * promotes "Type" to the top while everything else stays alpha.
24
- */
25
- order?: number;
26
- /**
27
- * Render this facet as a tree instead of a flat checkbox list.
28
- * See `buildFacetTree` for the two derivation strategies (slash-
29
- * encoded vs nav-driven segment-encoded) and the canonical
30
- * @dogsbay/types definition for full semantics.
31
- */
32
- hierarchical?: boolean;
33
- }
34
-
35
- /**
36
- * Minimal nav item shape — mirrors `@dogsbay/types`' `NavItem`
37
- * locally so this module has no runtime dependency on the types
38
- * package. Used as input to `buildFacetTree` for segment-encoded
39
- * facets (the auto-`category` case), where the document tree is
40
- * the source of structure and order.
41
- */
42
- export interface NavLike {
43
- label: string;
44
- href?: string;
45
- children?: NavLike[];
46
- }
47
-
48
- /** Map of taxonomy name → display config. */
49
- export type TaxonomyDisplayMap = Record<string, TaxonomyDisplay>;
50
-
51
- /** One facet entry — value plus the count of pages tagged with it. */
52
- export interface FacetEntry {
53
- /** The slug as Pagefind indexed it (e.g. `"concept/a11y"`, `"how-to"`). */
54
- value: string;
55
- /** Page count for this value within the current corpus. */
56
- count: number;
57
- }
58
-
59
- /** Map of facet name (taxonomy) → ordered entries. */
60
- export type FacetMap = Record<string, FacetEntry[]>;
8
+ export * from "@dogsbay/search/facets";
9
+ import type { FilterState } from "@dogsbay/search/facets";
61
10
 
62
11
  /**
63
12
  * Pagefind's filters API surface — a thin subset of the runtime
64
- * shape, kept local so this module stays dependency-free.
13
+ * shape, kept local so this module needs no Pagefind types.
65
14
  *
66
15
  * `pagefind.filters()` resolves to a nested map:
67
16
  * `{ <facetName>: { <value>: <count> } }`. We sort + flatten it.
@@ -70,171 +19,6 @@ export interface PagefindLike {
70
19
  filters(): Promise<Record<string, Record<string, number>>>;
71
20
  }
72
21
 
73
- /**
74
- * Convert Pagefind's nested filter map into a sorted `FacetMap`.
75
- *
76
- * Sort order: count descending, then value ascending alphabetically
77
- * (stable tie-break). Empty value lists are dropped — a facet with
78
- * zero values isn't worth a row in the UI. Returns an empty
79
- * `FacetMap` when Pagefind reports no filters at all (Pagefind log
80
- * still says "Indexed 0 filters" — usually means the head→body fix
81
- * hasn't propagated, not a real "no-tags" site).
82
- */
83
- export function shapeFacets(
84
- raw: Record<string, Record<string, number>> | undefined | null,
85
- ): FacetMap {
86
- if (!raw) return {};
87
- const out: FacetMap = {};
88
- for (const [name, valueMap] of Object.entries(raw)) {
89
- const entries = sortFacetEntries(
90
- Object.entries(valueMap).map(([value, count]) => ({ value, count })),
91
- );
92
- if (entries.length > 0) out[name] = entries;
93
- }
94
- return out;
95
- }
96
-
97
- /**
98
- * Sort facet entries by count descending, then by value
99
- * ascending alphabetically. Stable for equal-count values so
100
- * the UI doesn't shuffle between renders.
101
- */
102
- export function sortFacetEntries(entries: FacetEntry[]): FacetEntry[] {
103
- return [...entries].sort((a, b) => {
104
- if (a.count !== b.count) return b.count - a.count;
105
- return a.value.localeCompare(b.value);
106
- });
107
- }
108
-
109
- /**
110
- * Resolve the human display label for one facet value.
111
- *
112
- * Maps the slug-form value to the configured display string by
113
- * looking up the per-taxonomy display config. For slash-nested
114
- * values (`concept/a11y`), the resolution rules match
115
- * `<TagList>` chip rendering: explicit label override wins, then
116
- * prefix label for top-level segments, then leaf segment as a
117
- * final fallback.
118
- *
119
- * Slug paths are split into segments via `/`, mirroring how
120
- * taxonomies indexes terms.
121
- */
122
- export function resolveFacetLabel(
123
- facetName: string,
124
- value: string,
125
- display?: TaxonomyDisplayMap,
126
- ): string {
127
- const taxonomy = display?.[facetName];
128
- const fullPath = value.split("/").filter((s) => s.length > 0);
129
- return resolveTermLabel(fullPath, taxonomy?.prefixes, taxonomy?.labels);
130
- }
131
-
132
- /**
133
- * Resolve the display label for a facet name itself (the column
134
- * header text). Looks up `prefixes[facetName].label` for built-in
135
- * taxonomies (`tags` → "Tags"), falling back to a humanized
136
- * version of the facet name (`by-audience` → "By audience").
137
- *
138
- * Per-taxonomy `prefixes` aren't a perfect fit here (they're keyed
139
- * by the segment, not by the taxonomy itself), so this is a
140
- * separate humanizer. Future schema work can add an explicit
141
- * `taxonomies.<name>.displayName` field if writers want full
142
- * control.
143
- */
144
- export function resolveFacetTitle(facetName: string): string {
145
- return facetName
146
- .replace(/[-_]/g, " ")
147
- .replace(/\b\w/g, (c) => c.toUpperCase());
148
- }
149
-
150
- /**
151
- * Return facet names in sidebar render order.
152
- *
153
- * Pagefind's `filters()` map iterates in index-discovery order
154
- * (effectively the first page Pagefind happened to read), so without
155
- * sorting the column order is arbitrary and shifts between builds.
156
- * Order rule:
157
- * 1. Facets with a numeric `order` in their `TaxonomyDisplay`
158
- * come first, ascending — use this to pin "Type" or "Audience"
159
- * to the top regardless of name.
160
- * 2. Everything else sorts alphabetically by facet name.
161
- * Stable within each tier so ties don't shuffle.
162
- */
163
- export function sortFacetNames(
164
- names: string[],
165
- display?: TaxonomyDisplayMap,
166
- ): string[] {
167
- const withOrder = (name: string): number | undefined => {
168
- const o = display?.[name]?.order;
169
- return typeof o === "number" ? o : undefined;
170
- };
171
- return [...names].sort((a, b) => {
172
- const oa = withOrder(a);
173
- const ob = withOrder(b);
174
- if (oa !== undefined && ob !== undefined) {
175
- if (oa !== ob) return oa - ob;
176
- return a.localeCompare(b);
177
- }
178
- if (oa !== undefined) return -1;
179
- if (ob !== undefined) return 1;
180
- return a.localeCompare(b);
181
- });
182
- }
183
-
184
- // ── URL persistence ──────────────────────────────────────────────
185
-
186
- /**
187
- * Active filter state — keyed by facet name, value is the set of
188
- * selected slugs (multi-select per facet, AND across facets).
189
- */
190
- export type FilterState = Record<string, string[]>;
191
-
192
- /**
193
- * Build URLSearchParams from the current filter state. Each
194
- * facet:value combination produces one `filter=<name>:<value>`
195
- * entry, repeated per selection. The `q` query param is added
196
- * only when query is non-empty.
197
- *
198
- * Resulting URL is shareable — re-loading restores both the
199
- * search query AND active filters.
200
- */
201
- export function filterStateToUrlParams(
202
- query: string,
203
- filters: FilterState,
204
- ): URLSearchParams {
205
- const params = new URLSearchParams();
206
- if (query.trim().length > 0) params.set("q", query.trim());
207
- for (const [name, values] of Object.entries(filters)) {
208
- for (const value of values) {
209
- params.append("filter", `${name}:${value}`);
210
- }
211
- }
212
- return params;
213
- }
214
-
215
- /**
216
- * Parse `URLSearchParams` back into `{ query, filters }`. The
217
- * inverse of `filterStateToUrlParams`. Tolerant of malformed
218
- * `filter=...` entries — anything missing the `:` separator is
219
- * silently dropped (forward-compat with future schema).
220
- */
221
- export function parseFiltersFromUrl(
222
- params: URLSearchParams,
223
- ): { query: string; filters: FilterState } {
224
- const query = params.get("q") ?? "";
225
- const filters: FilterState = {};
226
- for (const raw of params.getAll("filter")) {
227
- const colonIdx = raw.indexOf(":");
228
- if (colonIdx < 1) continue; // need at least 1 char before the colon
229
- const name = raw.slice(0, colonIdx);
230
- const value = raw.slice(colonIdx + 1);
231
- if (!value) continue;
232
- if (!filters[name]) filters[name] = [];
233
- if (!filters[name].includes(value)) filters[name].push(value);
234
- }
235
- return { query, filters };
236
- }
237
-
238
22
  /**
239
23
  * Build Pagefind's `filters` argument from internal facet state.
240
24
  *
@@ -265,470 +49,3 @@ export function filterStateToPagefindFilters(
265
49
  }
266
50
  return out;
267
51
  }
268
-
269
- /**
270
- * Toggle a single (facetName, value) pair in the filter state.
271
- * Returns a new state object — the input is never mutated, so
272
- * callers can safely use this with React-style "set state to a
273
- * new value" patterns or vanilla state diffing.
274
- */
275
- export function toggleFilter(
276
- filters: FilterState,
277
- name: string,
278
- value: string,
279
- ): FilterState {
280
- const next: FilterState = { ...filters };
281
- const current = next[name] ?? [];
282
- if (current.includes(value)) {
283
- const dropped = current.filter((v) => v !== value);
284
- if (dropped.length === 0) {
285
- delete next[name];
286
- } else {
287
- next[name] = dropped;
288
- }
289
- } else {
290
- next[name] = [...current, value];
291
- }
292
- return next;
293
- }
294
-
295
- /**
296
- * Count the total number of active filter selections across all
297
- * facets. Used to render a "Clear all" button only when there's
298
- * something to clear.
299
- */
300
- export function countActiveFilters(filters: FilterState): number {
301
- let n = 0;
302
- for (const values of Object.values(filters)) n += values.length;
303
- return n;
304
- }
305
-
306
- // ── Hierarchical facets ──────────────────────────────────────────
307
-
308
- /**
309
- * One node in a hierarchical facet tree (see `buildFacetTree`).
310
- *
311
- * `value` is the canonical Pagefind filter value for this node —
312
- * for slash-encoded facets the full slash-joined path
313
- * (`concept/a11y`); for segment-encoded facets a single segment
314
- * (`installing_aws`). `value` matches Pagefind's value key 1:1
315
- * for "real" entries; synthetic parents (intermediate trie nodes
316
- * that don't correspond to a Pagefind entry) reuse the same
317
- * derived value but carry `hasValue: false` and `count: 0`.
318
- */
319
- export interface FacetTreeNode {
320
- value: string;
321
- label: string;
322
- count: number;
323
- depth: number;
324
- /** True if Pagefind reported this exact value; false for synthetic parents. */
325
- hasValue: boolean;
326
- children: FacetTreeNode[];
327
- }
328
-
329
- /**
330
- * Build a hierarchical facet tree from Pagefind's flat entry list.
331
- *
332
- * Two strategies depending on the values' shape:
333
- *
334
- * - **Slash-encoded.** When at least one entry value contains `/`,
335
- * each value is treated as a path through the tree (`concept/a11y`
336
- * → `concept → a11y`). Splits on `/`, inserts into a trie.
337
- * Parent entries that don't have a Pagefind value of their own
338
- * (e.g. `concept` standalone is unindexed but `concept/a11y` is)
339
- * appear as synthetic intermediate nodes with `hasValue: false`.
340
- * Within a parent, children sort by count desc then alpha — the
341
- * same rule as flat facets.
342
- *
343
- * - **Segment-encoded.** When NO entry contains `/`, each value is
344
- * a single path segment. Hierarchy comes from `nav` — every nav
345
- * leaf's href segments become a chain in the trie. Counts come
346
- * from Pagefind's entry list, attached to nodes whose segment
347
- * name matches an entry value. **Caveat:** Pagefind reports one
348
- * count per distinct segment name regardless of where in the
349
- * tree it lives, so a segment that appears at multiple positions
350
- * (`installing/.../ipi`, `installing_azure/.../ipi`) gets the
351
- * same total count at every position — clicking selects the
352
- * shared value, returning pages from every position. This
353
- * matches the underlying Pagefind filter behaviour and is
354
- * documented in plans/hierarchical-facets.md.
355
- *
356
- * Order is nav-document order, NOT count desc. Pagefind entries
357
- * not represented in nav are appended as orphans at the root in
358
- * alpha order.
359
- *
360
- * When `nav` is undefined for the segment-encoded case, falls
361
- * back to a flat list (every entry a root-level node with no
362
- * children, in count-desc order) — preserves render-ability
363
- * when nav.json hasn't loaded yet.
364
- *
365
- * Returns the top-level nodes. Empty `entries` → empty array.
366
- */
367
- export function buildFacetTree(
368
- facetName: string,
369
- entries: FacetEntry[],
370
- options: {
371
- nav?: NavLike[];
372
- display?: TaxonomyDisplayMap;
373
- } = {},
374
- ): FacetTreeNode[] {
375
- if (entries.length === 0) return [];
376
-
377
- const slashEncoded = entries.some((e) => e.value.includes("/"));
378
- if (slashEncoded) {
379
- // When nav is supplied, derive document-order. Otherwise fall
380
- // back to count-desc + alpha. The map keys are full cumulative
381
- // paths (matching Pagefind entry values 1:1).
382
- const navOrder = options.nav
383
- ? buildNavOrderMap(
384
- options.nav,
385
- new Set(entries.map((e) => e.value)),
386
- )
387
- : undefined;
388
- return buildSlashTree(facetName, entries, options.display, navOrder);
389
- }
390
- return buildSegmentTree(facetName, entries, options.nav, options.display);
391
- }
392
-
393
- /**
394
- * Slash-encoded tree builder. Each entry value is a slash-joined
395
- * path; split, walk a trie, attach Pagefind counts to terminal
396
- * nodes. Synthetic intermediate nodes (a path component used by a
397
- * descendant but absent from `entries`) get `hasValue: false` and
398
- * `count: 0` so they render but don't contribute to selection.
399
- *
400
- * Sort order at every depth:
401
- * 1. `navOrder` index if present (document order from nav.json).
402
- * Without this, deep API-reference subtrees with high page
403
- * counts would dominate the top of the tree even though they
404
- * sit at the BOTTOM of the rendered nav.
405
- * 2. Count desc (more pages → higher).
406
- * 3. Alpha (final tiebreak).
407
- */
408
- function buildSlashTree(
409
- facetName: string,
410
- entries: FacetEntry[],
411
- display?: TaxonomyDisplayMap,
412
- navOrder?: Map<string, number>,
413
- ): FacetTreeNode[] {
414
- // Trie keyed by full slash-path. Children are tracked on each
415
- // node's own `children` array (built unsorted in pass 1, sorted
416
- // recursively in pass 2).
417
- const byPath = new Map<string, FacetTreeNode>();
418
- const rootValues: string[] = [];
419
-
420
- for (const entry of entries) {
421
- const segments = entry.value.split("/").filter((s) => s.length > 0);
422
- if (segments.length === 0) continue;
423
- let pathSoFar = "";
424
- let parent: FacetTreeNode | null = null;
425
- for (let i = 0; i < segments.length; i++) {
426
- pathSoFar = pathSoFar ? `${pathSoFar}/${segments[i]}` : segments[i];
427
- let node = byPath.get(pathSoFar);
428
- if (!node) {
429
- node = {
430
- value: pathSoFar,
431
- label: resolveFacetLabel(facetName, pathSoFar, display),
432
- count: 0,
433
- depth: i,
434
- hasValue: false,
435
- children: [],
436
- };
437
- byPath.set(pathSoFar, node);
438
- if (parent) parent.children.push(node);
439
- else rootValues.push(pathSoFar);
440
- }
441
- if (i === segments.length - 1) {
442
- node.count = entry.count;
443
- node.hasValue = true;
444
- }
445
- parent = node;
446
- }
447
- }
448
-
449
- // Pass 2: sort children at every depth.
450
- const cmp = (a: FacetTreeNode, b: FacetTreeNode): number => {
451
- if (navOrder) {
452
- const oa = navOrder.get(a.value);
453
- const ob = navOrder.get(b.value);
454
- if (oa !== undefined && ob !== undefined && oa !== ob) return oa - ob;
455
- // Nodes IN the nav sort before nodes not in nav
456
- if (oa !== undefined && ob === undefined) return -1;
457
- if (oa === undefined && ob !== undefined) return 1;
458
- }
459
- if (a.count !== b.count) return b.count - a.count;
460
- return a.value.localeCompare(b.value);
461
- };
462
- const sortChildren = (node: FacetTreeNode): void => {
463
- if (node.children.length === 0) return;
464
- node.children.sort(cmp);
465
- for (const c of node.children) sortChildren(c);
466
- };
467
-
468
- const rootList = rootValues.map((v) => byPath.get(v)!);
469
- rootList.sort(cmp);
470
- for (const r of rootList) sortChildren(r);
471
- return rootList;
472
- }
473
-
474
- /**
475
- * Walk `nav` and assign each cumulative slash-path (matching a
476
- * Pagefind facet value in `knownValues`) a sequential index in
477
- * first-encounter order. Used by `buildSlashTree` to sort children
478
- * in document order rather than count-desc.
479
- *
480
- * Auto-detects and strips a leading basePath: for each nav leaf, we
481
- * try each starting offset of the href's parent segments. The first
482
- * offset whose initial cumulative path is in `knownValues` is the
483
- * "real" content root; the dropped prefix is the basePath. This way
484
- * the helper works on any site without needing the basePath threaded
485
- * through explicitly.
486
- *
487
- * Hrefs whose parents don't match anything in `knownValues` at any
488
- * offset are skipped (e.g. top-level pages with no auto-derived
489
- * category, or pages outside the indexed corpus).
490
- *
491
- * Exported for use by `buildFacetTree`. Pure — no I/O.
492
- */
493
- export function buildNavOrderMap(
494
- nav: NavLike[],
495
- knownValues: Set<string>,
496
- ): Map<string, number> {
497
- const order = new Map<string, number>();
498
- let n = 0;
499
- const walk = (items: NavLike[]): void => {
500
- for (const item of items) {
501
- if (item.href) {
502
- const parents = hrefToCategorySegments(item.href);
503
- // Try each starting offset; first one whose initial cumulative
504
- // path is in knownValues wins (auto-detects basePath).
505
- for (let start = 0; start < parents.length; start++) {
506
- const first = parents[start];
507
- if (!knownValues.has(first)) continue;
508
- // Record all cumulative paths starting from `start` that
509
- // exist in knownValues. The check at line below filters out
510
- // synthetic intermediates the corpus didn't tag (e.g. a
511
- // user-supplied frontmatter category that skipped a level).
512
- let cumulative = "";
513
- for (let i = start; i < parents.length; i++) {
514
- cumulative = cumulative ? `${cumulative}/${parents[i]}` : parents[i];
515
- if (knownValues.has(cumulative) && !order.has(cumulative)) {
516
- order.set(cumulative, n++);
517
- }
518
- }
519
- break;
520
- }
521
- }
522
- if (item.children && item.children.length > 0) walk(item.children);
523
- }
524
- };
525
- walk(nav);
526
- return order;
527
- }
528
-
529
- /**
530
- * Segment-encoded tree builder. Walks `nav` to discover the
531
- * canonical document hierarchy, then attaches Pagefind counts to
532
- * any node whose segment name matches an entry. Pagefind entries
533
- * not in nav are appended as alpha-sorted root orphans so they
534
- * don't disappear.
535
- */
536
- function buildSegmentTree(
537
- facetName: string,
538
- entries: FacetEntry[],
539
- nav: NavLike[] | undefined,
540
- display?: TaxonomyDisplayMap,
541
- ): FacetTreeNode[] {
542
- const byValue = new Map<string, FacetEntry>();
543
- for (const e of entries) byValue.set(e.value, e);
544
-
545
- if (!nav || nav.length === 0) {
546
- // Flat fallback in count-desc order — preserves render-ability
547
- // when nav hasn't loaded.
548
- return entries.map((e) => ({
549
- value: e.value,
550
- label: resolveFacetLabel(facetName, e.value, display),
551
- count: e.count,
552
- depth: 0,
553
- hasValue: true,
554
- children: [],
555
- }));
556
- }
557
-
558
- const seenValues = new Set<string>();
559
- const roots: FacetTreeNode[] = [];
560
- const rootIndex = new Map<string, FacetTreeNode>();
561
-
562
- /** Insert a path's parent segments (excluding the leaf filename) into the trie. */
563
- const insertPath = (segments: string[]): void => {
564
- if (segments.length === 0) return;
565
- let parentList: FacetTreeNode[] = roots;
566
- let parentIndex: Map<string, FacetTreeNode> = rootIndex;
567
- for (let i = 0; i < segments.length; i++) {
568
- const seg = segments[i];
569
- let node = parentIndex.get(seg);
570
- if (!node) {
571
- const entry = byValue.get(seg);
572
- node = {
573
- value: seg,
574
- label: resolveFacetLabel(facetName, seg, display),
575
- count: entry ? entry.count : 0,
576
- depth: i,
577
- hasValue: entry !== undefined,
578
- children: [],
579
- };
580
- parentList.push(node);
581
- parentIndex.set(seg, node);
582
- if (entry) seenValues.add(seg);
583
- }
584
- // Walk into the child list for the next iteration. Each
585
- // node carries its own child index lazily via a WeakMap-like
586
- // closure; here we use a regular Map keyed off the node.
587
- let nextIndex = childIndex.get(node);
588
- if (!nextIndex) {
589
- nextIndex = new Map();
590
- childIndex.set(node, nextIndex);
591
- }
592
- parentList = node.children;
593
- parentIndex = nextIndex;
594
- }
595
- };
596
-
597
- const childIndex = new Map<FacetTreeNode, Map<string, FacetTreeNode>>();
598
-
599
- // Walk every nav leaf. Use href segments (excluding the leaf
600
- // filename) — those are the auto-derived `category` values
601
- // emitted by parseMeta's deriveCategoryFromSlug.
602
- const walkNav = (items: NavLike[]): void => {
603
- for (const item of items) {
604
- if (item.href) {
605
- const parents = hrefToCategorySegments(item.href);
606
- insertPath(parents);
607
- }
608
- if (item.children && item.children.length > 0) walkNav(item.children);
609
- }
610
- };
611
- walkNav(nav);
612
-
613
- // Pagefind values not represented in nav → root-level orphans in
614
- // alpha order. Without this they vanish from the UI silently.
615
- const orphans: FacetTreeNode[] = [];
616
- for (const e of entries) {
617
- if (seenValues.has(e.value)) continue;
618
- orphans.push({
619
- value: e.value,
620
- label: resolveFacetLabel(facetName, e.value, display),
621
- count: e.count,
622
- depth: 0,
623
- hasValue: true,
624
- children: [],
625
- });
626
- }
627
- orphans.sort((a, b) => a.value.localeCompare(b.value));
628
- return [...roots, ...orphans];
629
- }
630
-
631
- /**
632
- * Strip an href down to its parent path segments — the `category`
633
- * derivation logic from `parseMeta.deriveCategoryFromSlug`. Drops
634
- * leading/trailing slashes, drops the leaf filename segment.
635
- */
636
- function hrefToCategorySegments(href: string): string[] {
637
- // Drop scheme/host if absolute (we only treat path segments)
638
- let path = href;
639
- try {
640
- if (/^[a-z]+:\/\//i.test(href)) path = new URL(href).pathname;
641
- } catch {
642
- // not a URL — treat as-is
643
- }
644
- // Drop hash + query — facets care about the URL path only
645
- path = path.split("#")[0].split("?")[0];
646
- const segments = path.split("/").filter((s) => s.length > 0);
647
- // Match deriveCategoryFromSlug: parents = everything except the leaf
648
- if (segments.length < 2) return [];
649
- return segments.slice(0, -1);
650
- }
651
-
652
- /**
653
- * Flat list of every "real" Pagefind value at or under `node`
654
- * (i.e. every node where `hasValue === true`). Synthetic parents
655
- * are excluded since adding them to the filter would be a no-op
656
- * (Pagefind has no pages tagged with the synthetic value).
657
- *
658
- * Used by `toggleTreeNode` when the user ticks a parent — we add
659
- * every real descendant value to the selection in one shot.
660
- */
661
- export function collectDescendantValues(node: FacetTreeNode): string[] {
662
- const out: string[] = [];
663
- const visit = (n: FacetTreeNode): void => {
664
- if (n.hasValue) out.push(n.value);
665
- for (const c of n.children) visit(c);
666
- };
667
- visit(node);
668
- return out;
669
- }
670
-
671
- /**
672
- * Tri-state of a tree node given the current filter state.
673
- *
674
- * - `"checked"` — every real descendant value (and self if
675
- * self has a value) is in `filters[facetName]`.
676
- * - `"unchecked"` — none of them are.
677
- * - `"indeterminate"`— at least one is, but not all.
678
- *
679
- * Synthetic parents with no real-value descendants resolve to
680
- * "unchecked" (defensive default — shouldn't occur in valid trees).
681
- */
682
- export function computeTreeState(
683
- node: FacetTreeNode,
684
- facetName: string,
685
- filters: FilterState,
686
- ): "checked" | "unchecked" | "indeterminate" {
687
- const descendants = collectDescendantValues(node);
688
- if (descendants.length === 0) return "unchecked";
689
- const selected = new Set(filters[facetName] ?? []);
690
- let hits = 0;
691
- for (const v of descendants) if (selected.has(v)) hits++;
692
- if (hits === 0) return "unchecked";
693
- if (hits === descendants.length) return "checked";
694
- return "indeterminate";
695
- }
696
-
697
- /**
698
- * Toggle a tree node's selection.
699
- *
700
- * - If currently checked → remove self + all descendant values
701
- * from `filters[facetName]`.
702
- * - If unchecked or indeterminate → add self + all descendant
703
- * values (auto-select). Matches the decided UX: parent click
704
- * fans out to children.
705
- *
706
- * Returns a new `FilterState` — input is not mutated. Same
707
- * immutability contract as `toggleFilter`.
708
- */
709
- export function toggleTreeNode(
710
- filters: FilterState,
711
- facetName: string,
712
- node: FacetTreeNode,
713
- currentState: "checked" | "unchecked" | "indeterminate",
714
- ): FilterState {
715
- const descendants = collectDescendantValues(node);
716
- if (descendants.length === 0) return filters;
717
- const current = filters[facetName] ?? [];
718
- let nextValues: string[];
719
- if (currentState === "checked") {
720
- const drop = new Set(descendants);
721
- nextValues = current.filter((v) => !drop.has(v));
722
- } else {
723
- const merged = new Set(current);
724
- for (const v of descendants) merged.add(v);
725
- nextValues = Array.from(merged);
726
- }
727
- const next: FilterState = { ...filters };
728
- if (nextValues.length === 0) {
729
- delete next[facetName];
730
- } else {
731
- next[facetName] = nextValues;
732
- }
733
- return next;
734
- }
@@ -20,7 +20,8 @@ export interface SiteChromeSocial {
20
20
  export interface SiteChromeData {
21
21
  colorMode?: "light" | "dark" | "system";
22
22
  logo?: { light: string; dark?: string; alt: string; replacesName: boolean };
23
- announcement?: { id: string; html: string; tone: string; closeable: boolean };
23
+ /** `key` (format-astro): the stored id, with the site's prefix; older site.json files have only `id`. */
24
+ announcement?: { id: string; key?: string; html: string; tone: string; closeable: boolean };
24
25
  header?: { links: Array<SiteChromeLink | SiteChromeMenu>; social: SiteChromeSocial[] };
25
26
  footer?: { columns: Array<{ title: string; links: SiteChromeLink[] }>; social: SiteChromeSocial[] };
26
27
  }
@@ -37,3 +38,26 @@ export const ANNOUNCEMENT_TONE_CLASS: Record<string, string> = {
37
38
  warning: "border-warning/40 bg-warning/20",
38
39
  caution: "border-danger/40 bg-danger/15",
39
40
  };
41
+
42
+ /** The width the header's links show in the bar from (in the sidebar's list below it); `never`: the list only. */
43
+ export type LinksFrom = "lg" | "xl" | "2xl" | "never";
44
+
45
+ /**
46
+ * Where the header's links fit: the first width at which their estimated width fits beside what
47
+ * else the header holds, or `never`. Estimated from the labels (about 6.2 px a character at the
48
+ * header's text size, 28 px padding a link, 14 px a dropdown's chevron) against the header beside
49
+ * the 256 px sidebar, less the trigger and padding (80 px) and the menus: about 520 px for a
50
+ * crowded header (product, version, page actions, icons), 210 px otherwise (search with its
51
+ * text, the icons). A crowded header starts at xl. Measured on Tigera's (47 characters, 4 links:
52
+ * xl) and the products fixture; a long navbar stays in the sidebar rather than push the page wide.
53
+ */
54
+ export function headerLinksFrom(links: Array<SiteChromeLink | SiteChromeMenu>, crowded: boolean): LinksFrom {
55
+ const est = links.reduce((n, l) => n + l.label.length * 6.2 + 28 + (isMenu(l) ? 14 : 0), 0);
56
+ const menus = crowded ? 520 : 210;
57
+ const widths: Array<[LinksFrom, number]> = [["lg", 1024], ["xl", 1280], ["2xl", 1536]];
58
+ for (const [from, width] of widths) {
59
+ if (crowded && from === "lg") continue;
60
+ if (est <= width - 256 - 80 - menus) return from;
61
+ }
62
+ return "never";
63
+ }
@@ -132,39 +132,11 @@ export function resolveTagKeywords(
132
132
  }
133
133
 
134
134
  /**
135
- * Resolve the display label for a term identified by its fullPath
136
- * array (e.g. `["concept"]` or `["concept", "a11y"]`).
137
- *
138
- * Used by `<TaxonomyIndex>` term-cloud chips, `<TaxonomyTerm>`
139
- * page headings and breadcrumbs, and sub-tag pills — anywhere a
140
- * structural slug needs to render as a human label.
141
- *
142
- * Resolution order:
143
- * 1. `labels[fullSlug]` (joined fullPath) — explicit override
144
- * wins, regardless of depth.
145
- * 2. For top-level terms (`fullPath.length === 1`):
146
- * `prefixes[segment].label` — lets a top-level segment
147
- * (`concept`, `difficulty`) render as "Concept", "Difficulty".
148
- * 3. The leaf segment of the path — the rendered fallback for
149
- * deeper terms with no override.
150
- *
151
- * URLs continue to use the slug-form `fullPath`. Display only.
135
+ * Display label of a term path (`labels` override, then a top-level
136
+ * `prefixes` label, then the leaf). One implementation, shared with the
137
+ * search facet column: `@dogsbay/search/facets`.
152
138
  */
153
- export function resolveTermLabel(
154
- fullPath: readonly string[],
155
- prefixes?: Record<string, PrefixDisplay>,
156
- labels?: Record<string, string>,
157
- ): string {
158
- if (fullPath.length === 0) return "";
159
- const slug = fullPath.join("/");
160
- const override = labels?.[slug];
161
- if (override && override.length > 0) return override;
162
- if (fullPath.length === 1) {
163
- const prefixLabel = prefixes?.[fullPath[0]]?.label;
164
- if (prefixLabel && prefixLabel.length > 0) return prefixLabel;
165
- }
166
- return fullPath[fullPath.length - 1];
167
- }
139
+ export { resolveTermLabel } from "@dogsbay/search/facets";
168
140
 
169
141
  /**
170
142
  * Map raw tag slugs to render-ready chip models, applying prefix