@dogsbay/docs-layout 0.2.0-beta.18 → 0.2.0-beta.181

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.
@@ -0,0 +1,122 @@
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-index.xml` link covers no-JS navigation —
21
+ * note `emitSitemapFiles` only runs when `site.url` is a valid
22
+ * http(s) URL, so a site without one has no sitemap for this
23
+ * fallback to reach.
24
+ * - First paint waits for the JS bundle + the JSON fetch. On a 4G
25
+ * connection that's typically <200 ms; the skeleton fills the
26
+ * space until then.
27
+ *
28
+ * See plans/client-rendered-nav.md.
29
+ */
30
+ interface Props {
31
+ /** Current page's URL pathname; the script uses it to mark the active item. */
32
+ currentPath: string;
33
+ /**
34
+ * URL prefix the host serves under (combined `urlBase` + `basePath`).
35
+ * The script joins this with `/_dogsbay/nav.json` to locate the
36
+ * fetchable nav tree; also threaded to the version/locale filter
37
+ * so multi-axis sites work the same as SSR.
38
+ */
39
+ basePath?: string;
40
+ /** Current source's product/namespace, if multi-product site. */
41
+ namespace?: string;
42
+ /** Current source's version axis value, if multi-version site. */
43
+ version?: string;
44
+ /** Current source's locale axis value, if multi-locale site. */
45
+ locale?: string;
46
+ /** The version served at the site root (`path: ""`), if any. */
47
+ rootVersion?: string;
48
+ /** The other versions' URL segments (left out of the root version's nav). */
49
+ versionSegments?: string[];
50
+ /** `"section"`: only the page's section, under the section menu (plans/nav-scope.md). */
51
+ navScope?: "site" | "section";
52
+ /** The home page, which lists the sections. */
53
+ home?: string;
54
+ /** An unlisted page: where it sits in the listed nav, to locate its section (plans/unlisted-pages.md). */
55
+ locatePath?: string;
56
+ }
57
+
58
+ const { currentPath, basePath = "", namespace, version, locale, rootVersion, versionSegments, navScope, home, locatePath } = Astro.props;
59
+ const navUrl = `${basePath}/_dogsbay/nav.json`;
60
+ ---
61
+
62
+ {/*
63
+ `role="navigation"` is REQUIRED here, not decoration: `aria-label` and
64
+ `aria-busy` are prohibited on a generic div (axe: aria-prohibited-attr,
65
+ serious) because a role-less element has no accessible name to label.
66
+ Giving the nav container its real role makes both attributes legal and
67
+ makes the landmark discoverable — it was previously neither.
68
+ */}
69
+ <div
70
+ id="docs-nav-root"
71
+ role="navigation"
72
+ data-nav-url={navUrl}
73
+ data-current-path={currentPath}
74
+ data-base-path={basePath}
75
+ data-namespace={namespace ?? ""}
76
+ data-version={version ?? ""}
77
+ data-locale={locale ?? ""}
78
+ data-root-version={rootVersion ?? ""}
79
+ data-version-segments={(versionSegments ?? []).join(" ")}
80
+ data-nav-scope={navScope === "section" ? "section" : undefined}
81
+ data-home={navScope === "section" ? (home ?? (basePath || "/")) : undefined}
82
+ data-locate-path={navScope === "section" && locatePath ? locatePath : undefined}
83
+ aria-busy="true"
84
+ aria-label="Documentation navigation"
85
+ >
86
+ <ul class="flex min-w-0 flex-col" data-sidebar="nav-tree" data-level="0">
87
+ {[0, 1, 2, 3, 4, 5].map((i) => (
88
+ <li>
89
+ <div
90
+ class="flex h-8 w-full items-center gap-2 rounded-md px-2"
91
+ aria-hidden="true"
92
+ >
93
+ <div class="h-2 w-2 rounded-full bg-sidebar-foreground/10" />
94
+ <div
95
+ class="h-2 rounded bg-sidebar-foreground/10"
96
+ style={`width: ${50 + ((i * 17) % 35)}%;`}
97
+ />
98
+ </div>
99
+ </li>
100
+ ))}
101
+ </ul>
102
+ <noscript>
103
+ <p class="px-2 py-1.5 text-sm text-sidebar-foreground/70">
104
+ JavaScript is required to render the sidebar. Use the
105
+ {/* sitemap-index.xml, not sitemap.xml — Dogsbay emits the
106
+ sitemap-index / sitemap-0 pair directly (see emitSitemapFiles);
107
+ `sitemap.xml` has never existed, so this no-JS fallback link
108
+ 404'd on every site. */}
109
+ <a href={`${basePath}/sitemap-index.xml`} class="underline">sitemap</a>
110
+ to browse all pages.
111
+ </p>
112
+ </noscript>
113
+ </div>
114
+
115
+ <script>
116
+ // Single import — Astro/Vite bundles this into one shared chunk
117
+ // referenced from every page that uses DocsNavClient. Browsers
118
+ // cache the chunk, so the nav script ships once per session
119
+ // regardless of how many pages the user visits.
120
+ import { hydrateDocsNav } from "./docs-nav-client.ts";
121
+ hydrateDocsNav();
122
+ </script>
package/src/DocsToc.astro CHANGED
@@ -33,7 +33,7 @@ const filtered = headings.filter(h => h.depth >= minDepth && h.depth <= maxDepth
33
33
 
34
34
  {filtered.length > 0 && (
35
35
  <nav class:list={["text-sm", className]} aria-label="Table of contents">
36
- <div class="text-xs font-semibold uppercase text-muted-foreground">{title}</div>
36
+ {title && <div class="text-xs font-semibold uppercase text-muted-foreground">{title}</div>}
37
37
  <ul class="mt-2 space-y-1">
38
38
  {filtered.map(h => (
39
39
  <li>
@@ -0,0 +1,80 @@
1
+ ---
2
+ /**
3
+ * The header's links (`header.links`): links, and one-level dropdowns as `<details>` lists like
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`, or `xl`), `layout="list"` for the sidebar below it.
6
+ */
7
+ import { isExternal, isMenu, type LinksFrom, type SiteChromeLink, type SiteChromeMenu } from "./site-chrome.js";
8
+
9
+ interface Props {
10
+ links: Array<SiteChromeLink | SiteChromeMenu>;
11
+ layout?: "bar" | "list";
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;
17
+ }
18
+ const { links, layout = "bar", currentPath, wrap = false, from = "lg" } = Astro.props;
19
+ // The page, or a page under the link's section; a link to the site's root only on the root itself
20
+ const current = (href: string) => {
21
+ if (!currentPath || isExternal(href)) return undefined;
22
+ const norm = (p: string) => (p.endsWith("/") ? p : `${p}/`);
23
+ const page = norm(currentPath);
24
+ const link = norm(href.replace(/[?#].*$/, ""));
25
+ return page === link || (link.split("/").filter(Boolean).length > 1 && page.startsWith(link)) ? "page" : undefined;
26
+ };
27
+ ---
28
+
29
+ {layout === "bar" ? (
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]]}>
31
+ {links.map((l) =>
32
+ isMenu(l) ? (
33
+ <details class="site-header-menu relative">
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">
35
+ {l.label}
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>
37
+ </summary>
38
+ <ul class="absolute left-0 z-50 mt-1 min-w-[12rem] rounded-md border border-border bg-popover p-1 text-sm shadow-md">
39
+ {l.items.map((i) => (
40
+ <li><a href={i.href} aria-current={current(i.href)} class="block rounded-sm px-2 py-1.5 text-foreground no-underline hover:bg-accent">{i.label}</a></li>
41
+ ))}
42
+ </ul>
43
+ </details>
44
+ ) : (
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>
46
+ ),
47
+ )}
48
+ </nav>
49
+ ) : (
50
+ <nav aria-label="Site" class="site-header-links-list">
51
+ <ul class="flex flex-col gap-0.5 text-sm">
52
+ {links.map((l) =>
53
+ isMenu(l) ? (
54
+ <li>
55
+ <span class="block px-2 py-1.5 text-xs font-medium text-sidebar-foreground/70">{l.label}</span>
56
+ <ul class="flex flex-col gap-0.5 pl-2">
57
+ {l.items.map((i) => (
58
+ <li><a href={i.href} aria-current={current(i.href)} class="block rounded-md px-2 py-1.5 text-sidebar-foreground no-underline hover:bg-sidebar-accent">{i.label}</a></li>
59
+ ))}
60
+ </ul>
61
+ </li>
62
+ ) : (
63
+ <li><a href={l.href} aria-current={current(l.href)} class="block rounded-md px-2 py-1.5 text-sidebar-foreground no-underline hover:bg-sidebar-accent">{l.label}</a></li>
64
+ ),
65
+ )}
66
+ </ul>
67
+ </nav>
68
+ )}
69
+
70
+ <style>
71
+ .site-header-menu > summary {
72
+ list-style: none;
73
+ }
74
+ .site-header-menu > summary::-webkit-details-marker {
75
+ display: none;
76
+ }
77
+ .site-header-menu[open] > summary > svg {
78
+ transform: rotate(180deg);
79
+ }
80
+ </style>
@@ -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"
@@ -0,0 +1,63 @@
1
+ ---
2
+ /**
3
+ * ProductSwitcher — the product menu of a site with a `products:` block and
4
+ * two or more products. Each entry opens that product's home; products do
5
+ * not share pages. A `<details>` list of links like VersionSwitcher: works
6
+ * without JS, and every entry is a link a crawler or screen reader follows.
7
+ * On a page outside every product it reads `placeholder` ("Product").
8
+ *
9
+ * Decision logic lives in `./switcher.ts` (`productMenu`), the same rules as
10
+ * dogsbay-ssg's product menu.
11
+ */
12
+ import { type SwitcherMap, type MultiSourceMeta, productMenu } from "./switcher.js";
13
+
14
+ interface Props {
15
+ switcherMap: SwitcherMap;
16
+ multiSource?: MultiSourceMeta;
17
+ placeholder?: string;
18
+ }
19
+
20
+ const { switcherMap, multiSource, placeholder = "Product" } = Astro.props;
21
+ const menu = productMenu(switcherMap, multiSource);
22
+ ---
23
+
24
+ {menu && (
25
+ <details class="product-switcher relative" data-product-switcher>
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
+ {menu.current && <span class="sr-only">{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
+ <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
+ </summary>
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">
32
+ {menu.entries.map((entry) => {
33
+ const isCurrent = entry.name === menu.current?.name;
34
+ return (
35
+ <li>
36
+ <a
37
+ href={entry.home}
38
+ aria-current={isCurrent ? "true" : undefined}
39
+ class:list={[
40
+ "flex items-center gap-2 rounded-sm px-2 py-1.5 no-underline",
41
+ isCurrent ? "bg-accent font-medium text-foreground" : "text-foreground hover:bg-accent",
42
+ ]}
43
+ >
44
+ {entry.label}
45
+ </a>
46
+ </li>
47
+ );
48
+ })}
49
+ </ul>
50
+ </details>
51
+ )}
52
+
53
+ <style>
54
+ .product-switcher > summary {
55
+ list-style: none;
56
+ }
57
+ .product-switcher > summary::-webkit-details-marker {
58
+ display: none;
59
+ }
60
+ .product-switcher[open] > summary > svg:last-child {
61
+ transform: rotate(180deg);
62
+ }
63
+ </style>