@dogsbay/docs-layout 0.2.0-beta.170 → 0.2.0-beta.171
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 +8 -7
- package/src/DocsLayout.astro +42 -1
- package/src/DocsNavClient.astro +7 -1
- package/src/docs-nav-client.ts +18 -2
- package/src/pagination.ts +7 -3
- package/src/section-switcher.ts +71 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dogsbay/docs-layout",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.171",
|
|
4
4
|
"description": "Standard documentation layout components for Dogsbay",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -32,14 +32,15 @@
|
|
|
32
32
|
"./AnnouncementBar.astro": "./src/AnnouncementBar.astro",
|
|
33
33
|
"./HeaderLinks.astro": "./src/HeaderLinks.astro",
|
|
34
34
|
"./SocialLinks.astro": "./src/SocialLinks.astro",
|
|
35
|
-
"./site-chrome": "./src/site-chrome.ts"
|
|
35
|
+
"./site-chrome": "./src/site-chrome.ts",
|
|
36
|
+
"./section-switcher": "./src/section-switcher.ts"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@dogsbay/elements": "0.2.0-beta.
|
|
39
|
-
"@dogsbay/primitives": "0.2.0-beta.
|
|
40
|
-
"@dogsbay/search": "0.2.0-beta.
|
|
41
|
-
"@dogsbay/site-files": "0.2.0-beta.
|
|
42
|
-
"@dogsbay/ui": "0.2.0-beta.
|
|
39
|
+
"@dogsbay/elements": "0.2.0-beta.171",
|
|
40
|
+
"@dogsbay/primitives": "0.2.0-beta.171",
|
|
41
|
+
"@dogsbay/search": "0.2.0-beta.171",
|
|
42
|
+
"@dogsbay/site-files": "0.2.0-beta.171",
|
|
43
|
+
"@dogsbay/ui": "0.2.0-beta.171"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"happy-dom": "^20.10.6",
|
package/src/DocsLayout.astro
CHANGED
|
@@ -56,7 +56,8 @@ import { filterNavByAxis, rootVersionFilter } from "./nav-filter.js";
|
|
|
56
56
|
import { versionBadge, versionBanner, type VersionBannerWording } from "./switcher.js";
|
|
57
57
|
import type { LlmProviderName } from "./llm-actions.js";
|
|
58
58
|
import { jsonLdTypeFor, normalizeCustomJsonLd, buildArticleJsonLd, buildWebSiteJsonLd } from "./json-ld.js";
|
|
59
|
-
import { pageFacets, type PageFacets } from "@dogsbay/site-files";
|
|
59
|
+
import { pageFacets, scopeNav, sectionMenu, type PageFacets } from "@dogsbay/site-files";
|
|
60
|
+
import { sectionSwitcherHtml } from "./section-switcher.js";
|
|
60
61
|
import { resolveTagKeywords } from "./tag-list-data.js";
|
|
61
62
|
|
|
62
63
|
interface NavItem {
|
|
@@ -424,6 +425,13 @@ interface Props {
|
|
|
424
425
|
* See plans/client-rendered-nav.md.
|
|
425
426
|
*/
|
|
426
427
|
navMode?: "client" | "ssr-full";
|
|
428
|
+
/**
|
|
429
|
+
* `"section"`: the sidebar holds only the page's section (the top-level
|
|
430
|
+
* nav entry that holds it), under a section menu and a link home; the home
|
|
431
|
+
* page and pages in no section list the sections. Default `"site"`.
|
|
432
|
+
* Rules: `scopeNav` in @dogsbay/site-files. See plans/nav-scope.md.
|
|
433
|
+
*/
|
|
434
|
+
navScope?: "site" | "section";
|
|
427
435
|
/**
|
|
428
436
|
* Per-page LLM action UI. When set and `enabled !== false`, renders
|
|
429
437
|
* the PageActions cluster (Copy markdown + Open in Claude/ChatGPT/
|
|
@@ -589,6 +597,7 @@ const {
|
|
|
589
597
|
switcherMap,
|
|
590
598
|
basePath,
|
|
591
599
|
navMode = "client",
|
|
600
|
+
navScope = "site",
|
|
592
601
|
wideLayout = false,
|
|
593
602
|
chrome = "docs",
|
|
594
603
|
author,
|
|
@@ -625,6 +634,28 @@ const badgeText = versionBadge(switcherMap as never, multiSource as never, versi
|
|
|
625
634
|
const bannerData = versionBanner(switcherMap as never, multiSource as never, versionBannerWording);
|
|
626
635
|
const navVersion = multiSource?.versionPath ? multiSource.versionPath : multiSource?.version;
|
|
627
636
|
|
|
637
|
+
// Section scope (build.navScope: section). In ssr-full the section and its
|
|
638
|
+
// menu are worked out here; in client mode docs-nav-client.ts does the same
|
|
639
|
+
// with the same functions. The home page lists the sections.
|
|
640
|
+
const navHome = basePath || "/";
|
|
641
|
+
const sectionScoped = navScope === "section";
|
|
642
|
+
const ssrSection = sectionScoped && navMode !== "client" && nav
|
|
643
|
+
? (() => {
|
|
644
|
+
const axisNav = filterNavByAxis(nav, {
|
|
645
|
+
basePath: basePath ?? "/docs",
|
|
646
|
+
namespace: multiSource?.namespace,
|
|
647
|
+
version: navVersion,
|
|
648
|
+
locale: multiSource?.locale,
|
|
649
|
+
...navRootVersion,
|
|
650
|
+
});
|
|
651
|
+
const opts = { home: navHome };
|
|
652
|
+
return {
|
|
653
|
+
items: scopeNav(axisNav, currentPath, "section", opts).items,
|
|
654
|
+
switcher: sectionSwitcherHtml({ ...sectionMenu(axisNav, currentPath, opts), homeHref: navHome }),
|
|
655
|
+
};
|
|
656
|
+
})()
|
|
657
|
+
: undefined;
|
|
658
|
+
|
|
628
659
|
// Link icons — classified in CSS by href shape. `data-link-icons`
|
|
629
660
|
// lists which kinds are active; the glyphs ride in CSS custom props
|
|
630
661
|
// (single-quoted so they're valid `content:` string values).
|
|
@@ -1190,9 +1221,19 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
|
|
1190
1221
|
locale={multiSource?.locale}
|
|
1191
1222
|
rootVersion={navRootVersion.rootVersion}
|
|
1192
1223
|
versionSegments={navRootVersion.versionSegments}
|
|
1224
|
+
navScope={navScope}
|
|
1225
|
+
home={navHome}
|
|
1193
1226
|
/>
|
|
1194
1227
|
</SidebarGroupContent>
|
|
1195
1228
|
</SidebarGroup>
|
|
1229
|
+
) : ssrSection ? (
|
|
1230
|
+
// One section's tree under its menu; group labels do not apply.
|
|
1231
|
+
<SidebarGroup>
|
|
1232
|
+
<SidebarGroupContent>
|
|
1233
|
+
<Fragment set:html={ssrSection.switcher} />
|
|
1234
|
+
<SidebarNavTree items={ssrSection.items} currentPath={currentPath} />
|
|
1235
|
+
</SidebarGroupContent>
|
|
1236
|
+
</SidebarGroup>
|
|
1196
1237
|
) : navGroups ? (
|
|
1197
1238
|
navGroups.map(group => (
|
|
1198
1239
|
<SidebarGroup>
|
package/src/DocsNavClient.astro
CHANGED
|
@@ -47,9 +47,13 @@ interface Props {
|
|
|
47
47
|
rootVersion?: string;
|
|
48
48
|
/** The other versions' URL segments (left out of the root version's nav). */
|
|
49
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;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
const { currentPath, basePath = "", namespace, version, locale, rootVersion, versionSegments } = Astro.props;
|
|
56
|
+
const { currentPath, basePath = "", namespace, version, locale, rootVersion, versionSegments, navScope, home } = Astro.props;
|
|
53
57
|
const navUrl = `${basePath}/_dogsbay/nav.json`;
|
|
54
58
|
---
|
|
55
59
|
|
|
@@ -71,6 +75,8 @@ const navUrl = `${basePath}/_dogsbay/nav.json`;
|
|
|
71
75
|
data-locale={locale ?? ""}
|
|
72
76
|
data-root-version={rootVersion ?? ""}
|
|
73
77
|
data-version-segments={(versionSegments ?? []).join(" ")}
|
|
78
|
+
data-nav-scope={navScope === "section" ? "section" : undefined}
|
|
79
|
+
data-home={navScope === "section" ? (home ?? (basePath || "/")) : undefined}
|
|
74
80
|
aria-busy="true"
|
|
75
81
|
aria-label="Documentation navigation"
|
|
76
82
|
>
|
package/src/docs-nav-client.ts
CHANGED
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
* See plans/client-rendered-nav.md.
|
|
24
24
|
*/
|
|
25
25
|
import { filterNavByAxis } from "./nav-filter.js";
|
|
26
|
+
import { scopeNav, sectionMenu } from "@dogsbay/site-files";
|
|
27
|
+
import { sectionSwitcherHtml } from "./section-switcher.js";
|
|
26
28
|
|
|
27
29
|
interface NavMark {
|
|
28
30
|
kind: "added" | "changed" | "removed" | "moved";
|
|
@@ -295,6 +297,17 @@ export function renderItem(item: NavItem, current: string, level: number): HTMLL
|
|
|
295
297
|
return li;
|
|
296
298
|
}
|
|
297
299
|
|
|
300
|
+
/**
|
|
301
|
+
* Section scope (`data-nav-scope="section"`): the page's section only, under
|
|
302
|
+
* the section menu — the same functions DocsLayout's server render uses.
|
|
303
|
+
*/
|
|
304
|
+
export function renderScoped(nav: NavItem[], current: string, home: string, root: HTMLElement): void {
|
|
305
|
+
const opts = { home };
|
|
306
|
+
renderTree(scopeNav(nav, current, "section", opts).items, current, root);
|
|
307
|
+
const menu = sectionSwitcherHtml({ ...sectionMenu(nav, current, opts), homeHref: home });
|
|
308
|
+
if (menu) root.insertAdjacentHTML("afterbegin", menu);
|
|
309
|
+
}
|
|
310
|
+
|
|
298
311
|
export function renderTree(items: NavItem[], current: string, root: HTMLElement): void {
|
|
299
312
|
const ul = document.createElement("ul");
|
|
300
313
|
ul.className =
|
|
@@ -397,7 +410,8 @@ export async function hydrateDocsNav(): Promise<void> {
|
|
|
397
410
|
locale: locale || undefined,
|
|
398
411
|
...(rootVersion ? { rootVersion, versionSegments } : {}),
|
|
399
412
|
});
|
|
400
|
-
|
|
413
|
+
if (root.dataset.navScope === "section") renderScoped(filtered, current, root.dataset.home || basePath || "/", root);
|
|
414
|
+
else renderTree(filtered, current, root);
|
|
401
415
|
} catch (err) {
|
|
402
416
|
console.error("docs-nav: hydration failed", err);
|
|
403
417
|
root.setAttribute("aria-busy", "false");
|
|
@@ -413,7 +427,9 @@ export async function hydrateDocsNav(): Promise<void> {
|
|
|
413
427
|
document.addEventListener("astro:page-load", () => {
|
|
414
428
|
const root = document.getElementById("docs-nav-root");
|
|
415
429
|
if (!root) return;
|
|
416
|
-
// If tree is already rendered (no aria-busy), just re-highlight.
|
|
430
|
+
// If tree is already rendered (no aria-busy), just re-highlight. (The root
|
|
431
|
+
// is not persisted across transitions, so a new page always hydrates, from
|
|
432
|
+
// the cached nav: a section-scoped sidebar is rebuilt for its own section.)
|
|
417
433
|
if (root.getAttribute("aria-busy") === null) {
|
|
418
434
|
const current = normalize(root.dataset.currentPath || location.pathname);
|
|
419
435
|
rehighlight(root, current);
|
package/src/pagination.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { scopeNav, type NavScope } from "@dogsbay/site-files";
|
|
2
|
+
|
|
1
3
|
interface NavItem {
|
|
2
4
|
label: string;
|
|
3
5
|
href?: string;
|
|
@@ -16,10 +18,12 @@ interface PaginationResult {
|
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* Flatten a nav tree into an ordered list of pages.
|
|
19
|
-
* Find prev/next for the given path.
|
|
21
|
+
* Find prev/next for the given path. With `scope: "section"` they walk the
|
|
22
|
+
* page's section only (`scopeNav`, shared with dogsbay-ssg), as its sidebar;
|
|
23
|
+
* `home` is the home page, which lists the sections.
|
|
20
24
|
*/
|
|
21
|
-
export function getPagination(currentPath: string, nav: NavItem[]): PaginationResult {
|
|
22
|
-
const allPages = flattenNav(nav);
|
|
25
|
+
export function getPagination(currentPath: string, nav: NavItem[], scope?: NavScope, home?: string): PaginationResult {
|
|
26
|
+
const allPages = flattenNav(scopeNav(nav, currentPath, scope, home === undefined ? {} : { home }).items);
|
|
23
27
|
const normalized = currentPath.replace(/\/$/, "") || "/";
|
|
24
28
|
const index = allPages.findIndex(p => p.href.replace(/\/$/, "") === normalized);
|
|
25
29
|
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The section menu of a sidebar scoped to one section (`build.navScope:
|
|
3
|
+
* section`): a link home, where the sidebar lists every section, and a
|
|
4
|
+
* `<details>` list of the sections like ProductSwitcher's, which works
|
|
5
|
+
* without JS. The markup is built HERE ONLY, as a string, so the server
|
|
6
|
+
* render (DocsLayout), the client-built sidebar (docs-nav-client.ts) and
|
|
7
|
+
* dogsbay-ssg (which copies this file, as it copies site-chrome.ts) cannot
|
|
8
|
+
* drift. No imports, so a copy runs on its own.
|
|
9
|
+
*
|
|
10
|
+
* The data comes from `sectionMenu` in @dogsbay/site-files.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export interface SectionSwitcherEntry {
|
|
14
|
+
label: string;
|
|
15
|
+
href: string;
|
|
16
|
+
/** The section's position (`sectionMenu` gives it): the current one is matched by it when set. */
|
|
17
|
+
index?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SectionSwitcherOptions {
|
|
21
|
+
entries: readonly SectionSwitcherEntry[];
|
|
22
|
+
/** The page's section; none on a page outside every section. */
|
|
23
|
+
current?: SectionSwitcherEntry;
|
|
24
|
+
/** The site's home page: where the sidebar lists every section. */
|
|
25
|
+
homeHref: string;
|
|
26
|
+
/** Default "All sections". */
|
|
27
|
+
homeLabel?: string;
|
|
28
|
+
/** Read before the section's name, and shown when there is none. Default "Section". */
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const ESC: Record<string, string> = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
33
|
+
function esc(s: string): string {
|
|
34
|
+
return s.replace(/[&<>"']/g, (c) => ESC[c]!);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const CHEVRON =
|
|
38
|
+
'<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="shrink-0 transition-transform group-open/section:rotate-180" aria-hidden="true"><polyline points="6 9 12 15 18 9"/></svg>';
|
|
39
|
+
const BACK =
|
|
40
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="15 18 9 12 15 6"/></svg>';
|
|
41
|
+
|
|
42
|
+
/** The menu's HTML; empty when there are no sections to list. */
|
|
43
|
+
export function sectionSwitcherHtml(o: SectionSwitcherOptions): string {
|
|
44
|
+
if (!o.entries.length) return "";
|
|
45
|
+
const placeholder = o.placeholder ?? "Section";
|
|
46
|
+
const home = o.homeLabel ?? "All sections";
|
|
47
|
+
const items = o.entries
|
|
48
|
+
.map((e) => {
|
|
49
|
+
const cur =
|
|
50
|
+
o.current !== undefined &&
|
|
51
|
+
(e.index !== undefined && o.current.index !== undefined ? e.index === o.current.index : e.href === o.current.href);
|
|
52
|
+
const cls = cur
|
|
53
|
+
? "flex rounded-sm px-2 py-1.5 no-underline bg-accent font-medium text-foreground"
|
|
54
|
+
: "flex rounded-sm px-2 py-1.5 no-underline text-foreground hover:bg-accent";
|
|
55
|
+
return `<li><a href="${esc(e.href)}"${cur ? ' aria-current="true"' : ""} class="${cls}">${esc(e.label)}</a></li>`;
|
|
56
|
+
})
|
|
57
|
+
.join("");
|
|
58
|
+
const name = o.current
|
|
59
|
+
? `<span class="sr-only">${esc(placeholder)}: </span><span class="min-w-0 flex-1 truncate text-left font-medium">${esc(o.current.label)}</span>`
|
|
60
|
+
: `<span class="min-w-0 flex-1 truncate text-left text-muted-foreground">${esc(placeholder)}</span>`;
|
|
61
|
+
return (
|
|
62
|
+
`<div class="db-section-switcher flex flex-col gap-1 px-2 pb-2 group-data-[collapsible=icon]:hidden" data-section-switcher>` +
|
|
63
|
+
(o.current
|
|
64
|
+
? `<a href="${esc(o.homeHref)}" class="flex items-center gap-1 px-1 text-xs text-sidebar-foreground/70 no-underline hover:text-sidebar-foreground" data-section-home>${BACK}${esc(home)}</a>`
|
|
65
|
+
: "") +
|
|
66
|
+
`<details class="group/section relative">` +
|
|
67
|
+
`<summary class="flex w-full cursor-pointer list-none items-center gap-1 rounded-md border border-border px-3 py-1.5 text-sm hover:bg-sidebar-accent [&::-webkit-details-marker]:hidden">${name}${CHEVRON}</summary>` +
|
|
68
|
+
`<ul class="absolute inset-x-0 z-50 mt-1 max-h-[60vh] overflow-y-auto rounded-md border border-border bg-popover p-1 text-sm shadow-md">${items}</ul>` +
|
|
69
|
+
`</details></div>`
|
|
70
|
+
);
|
|
71
|
+
}
|