@dogsbay/docs-layout 0.2.0-beta.8 → 0.2.0-beta.80

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.8",
3
+ "version": "0.2.0-beta.80",
4
4
  "description": "Standard documentation layout components for Dogsbay",
5
5
  "type": "module",
6
6
  "exports": {
@@ -29,14 +29,14 @@
29
29
  "./json-ld": "./src/json-ld.ts"
30
30
  },
31
31
  "dependencies": {
32
- "@dogsbay/ui": "0.2.0-beta.8",
33
- "@dogsbay/primitives": "0.2.0-beta.8"
32
+ "@dogsbay/ui": "0.2.0-beta.80",
33
+ "@dogsbay/primitives": "0.2.0-beta.80"
34
34
  },
35
35
  "devDependencies": {
36
36
  "vitest": "^3.0.0"
37
37
  },
38
38
  "peerDependencies": {
39
- "astro": "^5.0.0 || ^6.0.0"
39
+ "astro": "^5.0.0 || ^6.0.0 || ^7.0.0"
40
40
  },
41
41
  "files": [
42
42
  "src",
@@ -31,6 +31,7 @@ import SidebarMenuItem from "@dogsbay/ui/sidebar/SidebarMenuItem.astro";
31
31
  import SidebarMenuButton from "@dogsbay/ui/sidebar/SidebarMenuButton.astro";
32
32
  import SidebarSeparator from "@dogsbay/ui/sidebar/SidebarSeparator.astro";
33
33
  import SidebarNavTree from "@dogsbay/ui/sidebar/SidebarNavTree.astro";
34
+ import DocsNavClient from "./DocsNavClient.astro";
34
35
  import Separator from "@dogsbay/ui/separator/Separator.astro";
35
36
  import ThemeToggle from "@dogsbay/ui/theme-toggle/ThemeToggle.astro";
36
37
  import DocsToc from "./DocsToc.astro";
@@ -44,7 +45,7 @@ import VersionSwitcher from "./VersionSwitcher.astro";
44
45
  import LocaleSwitcher from "./LocaleSwitcher.astro";
45
46
  import { filterNavByAxis } from "./nav-filter.js";
46
47
  import type { LlmProviderName } from "./llm-actions.js";
47
- import { jsonLdTypeFor, normalizeCustomJsonLd } from "./json-ld.js";
48
+ import { jsonLdTypeFor, normalizeCustomJsonLd, buildArticleJsonLd } from "./json-ld.js";
48
49
  import { resolveTagKeywords } from "./tag-list-data.js";
49
50
 
50
51
  interface NavItem {
@@ -112,7 +113,13 @@ interface Props {
112
113
  siteDescription?: string;
113
114
  /** Copyright text (HTML allowed) */
114
115
  copyright?: string;
115
- /** Favicon path (default: "/favicon.ico"). Set to false to disable. */
116
+ /**
117
+ * Favicon path. No host-root default — that 404s on subpath
118
+ * deploys. The format-astro emitter passes a combined-prefix
119
+ * path (e.g. `/<repo>/favicon.ico`) computed from site.url +
120
+ * basePath. Pass an empty string or `false` to disable. When
121
+ * undefined, no `<link rel="icon">` is emitted.
122
+ */
116
123
  favicon?: string | false;
117
124
  /** Per-page OG image URL. Overrides defaultOgImage. */
118
125
  ogImage?: string;
@@ -127,16 +134,25 @@ interface Props {
127
134
  /** Theme color hint for browsers (hex string) */
128
135
  themeColor?: string;
129
136
  /**
130
- * Emit `<meta name="robots" content="noindex, nofollow">` when
137
+ * Emit `noindex` in the `<meta name="robots">` directive when
131
138
  * true. Tells external search engines (Google, Bing) to skip
132
- * this page. Has NO effect on in-site Pagefind search — for
133
- * that, use `excludeFromSearch`. The two are independent: a
134
- * page can be excluded from external SEs but still appear in
135
- * Pagefind (e.g. duplicate / old content readers might still
136
- * want to find when they're already on the site), or vice
137
- * versa.
139
+ * indexing this page. Independent of `nofollow` common pattern
140
+ * for tag / index pages is noindex + follow (don't list this
141
+ * page in results, but do crawl through to the real content).
142
+ *
143
+ * Has NO effect on in-site Pagefind search for that, use
144
+ * `excludeFromSearch`. The two are independent: a page can be
145
+ * excluded from external SEs but still appear in Pagefind (e.g.
146
+ * duplicate / old content readers might still want to find when
147
+ * they're already on the site), or vice versa.
138
148
  */
139
149
  noindex?: boolean;
150
+ /**
151
+ * Emit `nofollow` in the `<meta name="robots">` directive when
152
+ * true. Tells crawlers not to follow outbound links from this
153
+ * page. Independent of `noindex`. Default false.
154
+ */
155
+ nofollow?: boolean;
140
156
  /**
141
157
  * Exclude this page from in-site Pagefind search results.
142
158
  *
@@ -256,6 +272,23 @@ interface Props {
256
272
  * elements in `<body>`.
257
273
  */
258
274
  category?: string[];
275
+ /**
276
+ * Custom-taxonomy values from `meta.taxonomies` — anything declared
277
+ * in `taxonomies:` config that isn't one of the five hardcoded
278
+ * built-ins (`tags`, `category`, `audience`, `type`, `status`).
279
+ *
280
+ * Each entry becomes one `<div data-pagefind-filter="<name>:<value>">`
281
+ * inside the indexed body, so the search dialog grows a checkbox
282
+ * group for every custom taxonomy automatically. No extra config
283
+ * needed beyond declaring the taxonomy in `dogsbay.config.yml` —
284
+ * the search dialog discovers facets at index time and renders
285
+ * whatever Pagefind reports.
286
+ *
287
+ * Display labels for the checkboxes flow through
288
+ * `taxonomyDisplay[<name>]` (same prefix/label config that drives
289
+ * chip rendering elsewhere). When unset, raw slugs are shown.
290
+ */
291
+ taxonomies?: Record<string, string[]>;
259
292
  /**
260
293
  * Map of taxonomy name → index path for declared taxonomies.
261
294
  * Used to wire links from built-in field badges (TypeBadge,
@@ -324,6 +357,19 @@ interface Props {
324
357
  * (`<basePath>/<version>/`). Defaults to "/docs".
325
358
  */
326
359
  basePath?: string;
360
+ /**
361
+ * Sidebar navigation render mode.
362
+ *
363
+ * - `"client"` (default): emit the small `<DocsNavClient />` placeholder;
364
+ * the tree is hydrated from `/_dogsbay/nav.json` once per session.
365
+ * Page HTML shrinks dramatically at scale (~50 KB vs ~1.2 MB on a
366
+ * 2k-page site). No-JS users see a sitemap fallback link.
367
+ * - `"ssr-full"`: render the full nav tree into every page's HTML.
368
+ * Best for very small sites or strict no-JS / SEO contexts.
369
+ *
370
+ * See plans/client-rendered-nav.md.
371
+ */
372
+ navMode?: "client" | "ssr-full";
327
373
  /**
328
374
  * Per-page LLM action UI. When set and `enabled !== false`, renders
329
375
  * the PageActions cluster (Copy markdown + Open in Claude/ChatGPT/
@@ -376,7 +422,7 @@ const {
376
422
  editUrl,
377
423
  lastUpdated,
378
424
  copyright,
379
- favicon = "/favicon.ico",
425
+ favicon,
380
426
  ogImage,
381
427
  defaultOgImage,
382
428
  ogType = "article",
@@ -384,11 +430,18 @@ const {
384
430
  twitterHandle,
385
431
  themeColor,
386
432
  noindex,
433
+ nofollow,
387
434
  excludeFromSearch,
388
435
  plausibleDomain,
389
436
  plausibleScriptUrl,
390
437
  hideSearch = false,
391
- pagefindUrl = "/pagefind/",
438
+ // No default for pagefindUrl host-root absolute paths break on
439
+ // subpath-mounted deploys (GH Pages project pages, multi-mount
440
+ // Cloudflare). format-astro's emitter always passes the
441
+ // combined-prefix-aware URL; manual instantiation must too.
442
+ // Undefined here propagates to SearchDialog where the JS loader
443
+ // throws on first open instead of silently 404'ing the bundle.
444
+ pagefindUrl,
392
445
  mdMirror = false,
393
446
  tags,
394
447
  tagsIndexPath = "/tags",
@@ -398,6 +451,7 @@ const {
398
451
  pageType,
399
452
  audience,
400
453
  category,
454
+ taxonomies,
401
455
  taxonomyIndexPaths,
402
456
  taxonomyDisplay,
403
457
  autoH1,
@@ -407,6 +461,7 @@ const {
407
461
  multiSource,
408
462
  switcherMap,
409
463
  basePath,
464
+ navMode = "client",
410
465
  wideLayout = false,
411
466
  class: className,
412
467
  } = Astro.props;
@@ -428,6 +483,16 @@ const showLlmActionsInline =
428
483
  llmActionsEnabled
429
484
  && (llmActionsPlacement === "inline" || llmActionsPlacement === "both");
430
485
  const llmFooterLink = !!llmActions && llmActions.footerLink !== false;
486
+ // Per-mount llms.txt URL — Dogsbay emits `<basePath>/llms.txt`
487
+ // (sitemap-index pattern), so the footer link must be basePath-
488
+ // prefixed too. Falls back to `/llms.txt` when basePath is empty
489
+ // or unset, matching the platform's host-root single-site case.
490
+ const llmsLinkHrefResolved = (() => {
491
+ const bp = (basePath ?? "").replace(/\/+$/, "");
492
+ if (!bp) return "/llms.txt";
493
+ const prefix = bp.startsWith("/") ? bp : `/${bp}`;
494
+ return `${prefix}/llms.txt`;
495
+ })();
431
496
 
432
497
  // Compute href targets for the type / status badges. A field is
433
498
  // linkable only when (a) the user declared a `taxonomies.<field>`
@@ -453,9 +518,25 @@ const currentPath = Astro.url.pathname.replace(/\/$/, "") || "/";
453
518
  const metaDescription = description ?? siteDescription;
454
519
  const metaOgImage = ogImage ?? defaultOgImage;
455
520
  const isAbsoluteSiteUrl = /^https?:\/\//.test(siteUrl);
521
+ // Compose canonical from ORIGIN + pathname. siteUrl may carry a
522
+ // path component (the urlBase that drives Astro's `base` — see
523
+ // plans/astro-base-from-site-url.md), and Astro.url.pathname
524
+ // already includes that prefix. Naively concatenating siteUrl +
525
+ // pathname double-counts the urlBase (e.g. .../repo/repo/page).
526
+ // Strip path off siteUrl by reparsing as a URL.
527
+ let canonicalOrigin: string | undefined;
528
+ if (isAbsoluteSiteUrl) {
529
+ try {
530
+ const u = new URL(siteUrl);
531
+ canonicalOrigin = `${u.protocol}//${u.host}`;
532
+ } catch {
533
+ // Malformed siteUrl — fall back to the original (no path) behavior.
534
+ canonicalOrigin = siteUrl.replace(/\/$/, "");
535
+ }
536
+ }
456
537
  const computedCanonical = canonicalUrl
457
- ?? (isAbsoluteSiteUrl
458
- ? siteUrl.replace(/\/$/, "") + Astro.url.pathname
538
+ ?? (canonicalOrigin
539
+ ? canonicalOrigin + Astro.url.pathname
459
540
  : undefined);
460
541
 
461
542
  // Markdown mirror — append `.md` to the current path for the alternate link
@@ -482,15 +563,16 @@ const tagKeywords = resolveTagKeywords(tags, tagLabels);
482
563
  // search engines key off for educational / tutorial / reference
483
564
  // SERP rendering. See `json-ld.ts` for the full mapping table.
484
565
  const articleJsonLd = (ogType === "article" && tagKeywords.length > 0)
485
- ? {
486
- "@context": "https://schema.org",
487
- "@type": jsonLdTypeFor(pageType),
488
- headline: title,
489
- keywords: tagKeywords.join(", "),
490
- ...(metaDescription ? { description: metaDescription } : {}),
491
- ...(metaOgImage ? { image: metaOgImage } : {}),
492
- ...(computedCanonical ? { url: computedCanonical } : {}),
493
- }
566
+ ? buildArticleJsonLd({
567
+ type: jsonLdTypeFor(pageType),
568
+ title,
569
+ siteName,
570
+ keywords: tagKeywords,
571
+ description: metaDescription,
572
+ image: metaOgImage,
573
+ url: computedCanonical,
574
+ headings,
575
+ })
494
576
  : undefined;
495
577
 
496
578
  // `customJsonLd` accepts either a single object or an array.
@@ -510,11 +592,22 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
510
592
  <title>{title} | {siteName}</title>
511
593
 
512
594
  {metaDescription && <meta name="description" content={metaDescription} />}
513
- {favicon !== false && <link rel="icon" href={favicon} />}
595
+ {favicon && <link rel="icon" href={favicon} />}
514
596
  {themeColor && <meta name="theme-color" content={themeColor} />}
515
597
  {/* External search engine directive — orthogonal to in-site
516
- Pagefind exclusion. */}
517
- {noindex && <meta name="robots" content="noindex, nofollow" />}
598
+ Pagefind exclusion. `noindex` + `nofollow` are independent
599
+ bits per the meta-robots spec; emit only the directives that
600
+ are set. Combining them when both are set keeps the tag
601
+ compact (`<meta name="robots" content="noindex, nofollow">`)
602
+ instead of emitting two tags. */}
603
+ {(noindex || nofollow) && (
604
+ <meta
605
+ name="robots"
606
+ content={[noindex && "noindex", nofollow && "nofollow"]
607
+ .filter(Boolean)
608
+ .join(", ")}
609
+ />
610
+ )}
518
611
 
519
612
  {/* In-site Pagefind exclusion is wired via two coordinated
520
613
  attributes on <body> and <main> below — see the prop docs
@@ -529,6 +622,12 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
529
622
 
530
623
  {computedCanonical && <link rel="canonical" href={computedCanonical} />}
531
624
  {mdMirrorHref && <link rel="alternate" type="text/markdown" href={mdMirrorHref} />}
625
+ {/* Programmatic llms.txt discovery — agents that follow head
626
+ link rels get the per-mount llms.txt without parsing HTML.
627
+ Mirrors the existing _headers Link rel="describedby" used by
628
+ Cloudflare Pages / Workers. */}
629
+ <link rel="alternate" type="text/plain" title="llms.txt" href={llmsLinkHrefResolved} />
630
+ <link rel="describedby" type="text/plain" href={llmsLinkHrefResolved} />
532
631
 
533
632
  {/* Open Graph */}
534
633
  <meta property="og:type" content={ogType} />
@@ -592,7 +691,7 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
592
691
  <SidebarHeader>
593
692
  <SidebarMenu>
594
693
  <SidebarMenuItem>
595
- <SidebarMenuButton size="lg" href={siteUrl} isActive={currentPath === siteUrl || currentPath === "/"}>
694
+ <SidebarMenuButton size="lg" href={basePath || "/"} isActive={currentPath === basePath || currentPath === "/"}>
596
695
  <div class="flex aspect-square size-8 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground">
597
696
  <Fragment set:html={siteIcon} />
598
697
  </div>
@@ -608,7 +707,24 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
608
707
  <SidebarSeparator />
609
708
 
610
709
  <SidebarContent>
611
- {navGroups ? (
710
+ {navMode === "client" ? (
711
+ // Client-render mode: emit one DocsNavClient placeholder
712
+ // inside a single SidebarGroup, regardless of navGroups.
713
+ // The group-label shape doesn't apply when the tree is
714
+ // hydrated by JS — multi-group nav is reconstructed
715
+ // client-side from the same /_dogsbay/nav.json shape.
716
+ // See plans/client-rendered-nav.md.
717
+ <SidebarGroup>
718
+ <SidebarGroupContent>
719
+ <DocsNavClient
720
+ currentPath={currentPath}
721
+ basePath={basePath ?? ""}
722
+ version={multiSource?.version}
723
+ locale={multiSource?.locale}
724
+ />
725
+ </SidebarGroupContent>
726
+ </SidebarGroup>
727
+ ) : navGroups ? (
612
728
  navGroups.map(group => (
613
729
  <SidebarGroup>
614
730
  <SidebarGroupLabel>{group.label}</SidebarGroupLabel>
@@ -676,6 +792,7 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
676
792
  {!hideSearch && (
677
793
  <SearchDialog
678
794
  pagefindUrl={pagefindUrl}
795
+ navUrl={basePath ? `${basePath}/_dogsbay/nav.json` : "/_dogsbay/nav.json"}
679
796
  taxonomyDisplay={taxonomyDisplay}
680
797
  />
681
798
  )}
@@ -709,9 +826,30 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
709
826
  the actual page content. Filter elements live in here
710
827
  now to stay inside that scope.
711
828
  */}
712
- {Array.isArray(tags) && tags.map((tag) => (
713
- <div hidden data-pagefind-filter={`tag:${tag}`}></div>
714
- ))}
829
+ {/*
830
+ Slash-nested tags whose prefix is declared in
831
+ `taxonomies.tags.prefixes` emit as per-prefix filter
832
+ divs so each prefix becomes its own Pagefind facet
833
+ column (Difficulty, Topic, Persona, …) instead of
834
+ pooling under a single "Tag" column.
835
+
836
+ Plain tags and tags whose prefix isn't declared fall
837
+ back to the pooled `tag:` filter — backward-compatible
838
+ for sites that haven't declared prefixes.
839
+
840
+ See plans/per-prefix-search-facets.md.
841
+ */}
842
+ {Array.isArray(tags) && tags.map((tag) => {
843
+ const slash = tag.indexOf("/");
844
+ if (slash > 0) {
845
+ const prefix = tag.slice(0, slash);
846
+ const leaf = tag.slice(slash + 1);
847
+ if (tagPrefixes && tagPrefixes[prefix]) {
848
+ return <div hidden data-pagefind-filter={`${prefix}:${leaf}`}></div>;
849
+ }
850
+ }
851
+ return <div hidden data-pagefind-filter={`tag:${tag}`}></div>;
852
+ })}
715
853
  {Array.isArray(audience) && audience.map((value) => (
716
854
  <div hidden data-pagefind-filter={`audience:${value}`}></div>
717
855
  ))}
@@ -720,6 +858,20 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
720
858
  ))}
721
859
  {status && <div hidden data-pagefind-filter={`status:${status}`}></div>}
722
860
  {pageType && <div hidden data-pagefind-filter={`type:${pageType}`}></div>}
861
+ {/*
862
+ Custom-taxonomy filters. Any taxonomy declared in
863
+ `dogsbay.config.yml` that isn't one of the five built-ins
864
+ flows through here, so `difficulty: intermediate` (etc.)
865
+ becomes a real Pagefind facet checkbox automatically.
866
+ See plans/beta-launch-followups.md for context.
867
+ */}
868
+ {taxonomies && Object.entries(taxonomies).flatMap(([name, values]) =>
869
+ Array.isArray(values)
870
+ ? values.map((value) => (
871
+ <div hidden data-pagefind-filter={`${name}:${value}`}></div>
872
+ ))
873
+ : []
874
+ )}
723
875
 
724
876
  <div class:list={["mx-auto", wideLayout ? "max-w-7xl" : "max-w-3xl"]}>
725
877
  {/*
@@ -802,6 +954,7 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
802
954
  next={next}
803
955
  copyright={copyright}
804
956
  llmsLink={llmFooterLink}
957
+ llmsLinkHref={llmsLinkHrefResolved}
805
958
  />
806
959
  </div>
807
960
  </main>
@@ -0,0 +1,89 @@
1
+ ---
2
+ /**
3
+ * Client-rendered drop-in replacement for SidebarNavTree.
4
+ *
5
+ * Emits an empty placeholder with the metadata the hydration script
6
+ * needs (nav-url to fetch, current-path to highlight, basePath for
7
+ * version/locale filtering). The actual tree DOM is rendered by
8
+ * `docs-nav-client.ts` after a single fetch of `nav.json` (cached
9
+ * once per session — subsequent navigations re-highlight without
10
+ * re-fetching, courtesy of view transitions).
11
+ *
12
+ * The placeholder shows a few skeleton rows so the layout doesn't
13
+ * shift when the real tree pops in. Skeleton uses the same width as
14
+ * the sidebar so visual jump is minimal even on a slow connection.
15
+ *
16
+ * Trade-offs vs SidebarNavTree:
17
+ * - HTML per page: ~200 bytes (this placeholder + a tiny script
18
+ * tag) vs ~600 KB+ for the SSR tree at scale.
19
+ * - No-JS users see only the skeleton + the `<noscript>` fallback
20
+ * link. A `sitemap.xml` link covers no-JS navigation.
21
+ * - First paint waits for the JS bundle + the JSON fetch. On a 4G
22
+ * connection that's typically <200 ms; the skeleton fills the
23
+ * space until then.
24
+ *
25
+ * See plans/client-rendered-nav.md.
26
+ */
27
+ interface Props {
28
+ /** Current page's URL pathname; the script uses it to mark the active item. */
29
+ currentPath: string;
30
+ /**
31
+ * URL prefix the host serves under (combined `urlBase` + `basePath`).
32
+ * The script joins this with `/_dogsbay/nav.json` to locate the
33
+ * fetchable nav tree; also threaded to the version/locale filter
34
+ * so multi-axis sites work the same as SSR.
35
+ */
36
+ basePath?: string;
37
+ /** Current source's version axis value, if multi-version site. */
38
+ version?: string;
39
+ /** Current source's locale axis value, if multi-locale site. */
40
+ locale?: string;
41
+ }
42
+
43
+ const { currentPath, basePath = "", version, locale } = Astro.props;
44
+ const navUrl = `${basePath}/_dogsbay/nav.json`;
45
+ ---
46
+
47
+ <div
48
+ id="docs-nav-root"
49
+ data-nav-url={navUrl}
50
+ data-current-path={currentPath}
51
+ data-base-path={basePath}
52
+ data-version={version ?? ""}
53
+ data-locale={locale ?? ""}
54
+ aria-busy="true"
55
+ aria-label="Documentation navigation"
56
+ >
57
+ <ul class="flex min-w-0 flex-col" data-sidebar="nav-tree" data-level="0">
58
+ {[0, 1, 2, 3, 4, 5].map((i) => (
59
+ <li>
60
+ <div
61
+ class="flex h-8 w-full items-center gap-2 rounded-md px-2"
62
+ aria-hidden="true"
63
+ >
64
+ <div class="h-2 w-2 rounded-full bg-sidebar-foreground/10" />
65
+ <div
66
+ class="h-2 rounded bg-sidebar-foreground/10"
67
+ style={`width: ${50 + ((i * 17) % 35)}%;`}
68
+ />
69
+ </div>
70
+ </li>
71
+ ))}
72
+ </ul>
73
+ <noscript>
74
+ <p class="px-2 py-1.5 text-sm text-sidebar-foreground/70">
75
+ JavaScript is required to render the sidebar. Use the
76
+ <a href={`${basePath}/sitemap.xml`} class="underline">sitemap</a>
77
+ to browse all pages.
78
+ </p>
79
+ </noscript>
80
+ </div>
81
+
82
+ <script>
83
+ // Single import — Astro/Vite bundles this into one shared chunk
84
+ // referenced from every page that uses DocsNavClient. Browsers
85
+ // cache the chunk, so the nav script ships once per session
86
+ // regardless of how many pages the user visits.
87
+ import { hydrateDocsNav } from "./docs-nav-client.ts";
88
+ hydrateDocsNav();
89
+ </script>