@dogsbay/docs-layout 0.2.0-beta.172 → 0.2.0-beta.174

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.172",
3
+ "version": "0.2.0-beta.174",
4
4
  "description": "Standard documentation layout components for Dogsbay",
5
5
  "type": "module",
6
6
  "exports": {
@@ -37,11 +37,11 @@
37
37
  "./section-switcher.css": "./src/section-switcher.css"
38
38
  },
39
39
  "dependencies": {
40
- "@dogsbay/elements": "0.2.0-beta.172",
41
- "@dogsbay/primitives": "0.2.0-beta.172",
42
- "@dogsbay/search": "0.2.0-beta.172",
43
- "@dogsbay/site-files": "0.2.0-beta.172",
44
- "@dogsbay/ui": "0.2.0-beta.172"
40
+ "@dogsbay/elements": "0.2.0-beta.174",
41
+ "@dogsbay/primitives": "0.2.0-beta.174",
42
+ "@dogsbay/search": "0.2.0-beta.174",
43
+ "@dogsbay/site-files": "0.2.0-beta.174",
44
+ "@dogsbay/ui": "0.2.0-beta.174"
45
45
  },
46
46
  "devDependencies": {
47
47
  "happy-dom": "^20.10.6",
@@ -433,6 +433,12 @@ interface Props {
433
433
  * Rules: `scopeNav` in @dogsbay/site-files. See plans/nav-scope.md.
434
434
  */
435
435
  navScope?: "site" | "section";
436
+ /**
437
+ * An unlisted page (plans/unlisted-pages.md) is in no listed nav entry: this is where it sits
438
+ * instead, its nearest listed ancestor's link, which locates its section for `navScope:
439
+ * "section"`. Nothing in the sidebar is marked current on such a page.
440
+ */
441
+ navLocate?: string;
436
442
  /**
437
443
  * Per-page LLM action UI. When set and `enabled !== false`, renders
438
444
  * the PageActions cluster (Copy markdown + Open in Claude/ChatGPT/
@@ -599,6 +605,7 @@ const {
599
605
  basePath,
600
606
  navMode = "client",
601
607
  navScope = "site",
608
+ navLocate,
602
609
  wideLayout = false,
603
610
  chrome = "docs",
604
611
  author,
@@ -650,9 +657,11 @@ const ssrSection = sectionScoped && navMode !== "client" && nav
650
657
  ...navRootVersion,
651
658
  });
652
659
  const opts = { home: navHome };
660
+ // An unlisted page is located by where it sits (navLocate), not by its own path
661
+ const locate = navLocate ?? currentPath;
653
662
  return {
654
- items: scopeNav(axisNav, currentPath, "section", opts).items,
655
- switcher: sectionSwitcherHtml({ ...sectionMenu(axisNav, currentPath, opts), homeHref: navHome }),
663
+ items: scopeNav(axisNav, locate, "section", opts).items,
664
+ switcher: sectionSwitcherHtml({ ...sectionMenu(axisNav, locate, opts), homeHref: navHome }),
656
665
  };
657
666
  })()
658
667
  : undefined;
@@ -1224,6 +1233,7 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
1224
1233
  versionSegments={navRootVersion.versionSegments}
1225
1234
  navScope={navScope}
1226
1235
  home={navHome}
1236
+ locatePath={navLocate}
1227
1237
  />
1228
1238
  </SidebarGroupContent>
1229
1239
  </SidebarGroup>
@@ -51,9 +51,11 @@ interface Props {
51
51
  navScope?: "site" | "section";
52
52
  /** The home page, which lists the sections. */
53
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;
54
56
  }
55
57
 
56
- const { currentPath, basePath = "", namespace, version, locale, rootVersion, versionSegments, navScope, home } = Astro.props;
58
+ const { currentPath, basePath = "", namespace, version, locale, rootVersion, versionSegments, navScope, home, locatePath } = Astro.props;
57
59
  const navUrl = `${basePath}/_dogsbay/nav.json`;
58
60
  ---
59
61
 
@@ -77,6 +79,7 @@ const navUrl = `${basePath}/_dogsbay/nav.json`;
77
79
  data-version-segments={(versionSegments ?? []).join(" ")}
78
80
  data-nav-scope={navScope === "section" ? "section" : undefined}
79
81
  data-home={navScope === "section" ? (home ?? (basePath || "/")) : undefined}
82
+ data-locate-path={navScope === "section" && locatePath ? locatePath : undefined}
80
83
  aria-busy="true"
81
84
  aria-label="Documentation navigation"
82
85
  >
@@ -301,10 +301,11 @@ export function renderItem(item: NavItem, current: string, level: number): HTMLL
301
301
  * Section scope (`data-nav-scope="section"`): the page's section only, under
302
302
  * the section menu — the same functions DocsLayout's server render uses.
303
303
  */
304
- export function renderScoped(nav: NavItem[], current: string, home: string, root: HTMLElement): void {
304
+ export function renderScoped(nav: NavItem[], current: string, home: string, root: HTMLElement, locate: string = current): void {
305
305
  const opts = { home };
306
- renderTree(scopeNav(nav, current, "section", opts).items, current, root);
307
- const menu = sectionSwitcherHtml({ ...sectionMenu(nav, current, opts), homeHref: home });
306
+ // `locate`: an unlisted page's place in the listed nav (data-locate-path); it marks nothing current
307
+ renderTree(scopeNav(nav, locate, "section", opts).items, current, root);
308
+ const menu = sectionSwitcherHtml({ ...sectionMenu(nav, locate, opts), homeHref: home });
308
309
  if (menu) root.insertAdjacentHTML("afterbegin", menu);
309
310
  }
310
311
 
@@ -410,7 +411,10 @@ export async function hydrateDocsNav(): Promise<void> {
410
411
  locale: locale || undefined,
411
412
  ...(rootVersion ? { rootVersion, versionSegments } : {}),
412
413
  });
413
- if (root.dataset.navScope === "section") renderScoped(filtered, current, root.dataset.home || basePath || "/", root);
414
+ if (root.dataset.navScope === "section") {
415
+ const locate = root.dataset.locatePath ? normalize(root.dataset.locatePath) : current;
416
+ renderScoped(filtered, current, root.dataset.home || basePath || "/", root, locate);
417
+ }
414
418
  else renderTree(filtered, current, root);
415
419
  } catch (err) {
416
420
  console.error("docs-nav: hydration failed", err);
package/src/pagination.ts CHANGED
@@ -24,9 +24,14 @@ interface PaginationResult {
24
24
  */
25
25
  export function getPagination(currentPath: string, nav: NavItem[], scope?: NavScope, home?: string): PaginationResult {
26
26
  const allPages = flattenNav(scopeNav(nav, currentPath, scope, home === undefined ? {} : { home }).items);
27
- const normalized = currentPath.replace(/\/$/, "") || "/";
28
- const index = allPages.findIndex(p => p.href.replace(/\/$/, "") === normalized);
27
+ // A root-served site's home entry is `""` (the importer's form): it is `/`
28
+ const norm = (href: string) => href.replace(/\/$/, "") || "/";
29
+ const normalized = norm(currentPath);
30
+ const index = allPages.findIndex(p => norm(p.href) === normalized);
29
31
 
32
+ // A page in no listed entry (an unlisted page, a page outside the nav) has neither: `-1` gave
33
+ // it the first page as its Next
34
+ if (index < 0) return { prev: undefined, next: undefined };
30
35
  return {
31
36
  prev: index > 0 ? allPages[index - 1] : undefined,
32
37
  next: index < allPages.length - 1 ? allPages[index + 1] : undefined,
@@ -36,7 +41,8 @@ export function getPagination(currentPath: string, nav: NavItem[], scope?: NavSc
36
41
  function flattenNav(items: NavItem[]): PaginationLink[] {
37
42
  const result: PaginationLink[] = [];
38
43
  for (const item of items) {
39
- if (item.href) result.push({ label: item.label, href: item.href });
44
+ // `!== undefined`: the home page's href is `""` on a root-served site, and is a page
45
+ if (item.href !== undefined) result.push({ label: item.label, href: item.href });
40
46
  if (item.children) result.push(...flattenNav(item.children));
41
47
  }
42
48
  return result;