@dogsbay/docs-layout 0.2.0-beta.87 → 0.2.0-beta.89
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 +3 -3
- package/src/DocsLayout.astro +5 -2
- package/src/toc-placement.ts +20 -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.89",
|
|
4
4
|
"description": "Standard documentation layout components for Dogsbay",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"./json-ld": "./src/json-ld.ts"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@dogsbay/ui": "0.2.0-beta.
|
|
33
|
-
"@dogsbay/primitives": "0.2.0-beta.
|
|
32
|
+
"@dogsbay/ui": "0.2.0-beta.89",
|
|
33
|
+
"@dogsbay/primitives": "0.2.0-beta.89"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"vitest": "^3.0.0"
|
package/src/DocsLayout.astro
CHANGED
|
@@ -35,7 +35,7 @@ import DocsNavClient from "./DocsNavClient.astro";
|
|
|
35
35
|
import Separator from "@dogsbay/ui/separator/Separator.astro";
|
|
36
36
|
import ThemeToggle from "@dogsbay/ui/theme-toggle/ThemeToggle.astro";
|
|
37
37
|
import DocsToc from "./DocsToc.astro";
|
|
38
|
-
import { resolveTocPlacement, type TocMode } from "./toc-placement.js";
|
|
38
|
+
import { resolveTocPlacement, hasDisplayableToc, type TocMode } from "./toc-placement.js";
|
|
39
39
|
import DocsFooter from "./DocsFooter.astro";
|
|
40
40
|
import SearchDialog from "./SearchDialog.astro";
|
|
41
41
|
import TagList from "./TagList.astro";
|
|
@@ -528,7 +528,10 @@ const hasMetaStrip = (
|
|
|
528
528
|
// TOC placement: which container(s) + the right-rail plugin region render.
|
|
529
529
|
// Logic lives in toc-placement.ts so it's unit-tested; this file just consumes.
|
|
530
530
|
const tocPlacement = resolveTocPlacement(toc, {
|
|
531
|
-
|
|
531
|
+
// Only show a TOC when the page has 2+ displayable headings (depth 2–3);
|
|
532
|
+
// the H1 doesn't count and a one-item TOC is noise. Keeps "On this page"
|
|
533
|
+
// off landing/welcome pages that are just an H1 + prose.
|
|
534
|
+
hasHeadings: hasDisplayableToc(headings),
|
|
532
535
|
wideLayout: !!wideLayout,
|
|
533
536
|
});
|
|
534
537
|
|
package/src/toc-placement.ts
CHANGED
|
@@ -25,6 +25,26 @@ export interface TocPlacement {
|
|
|
25
25
|
regionRail: boolean;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Whether a page has enough displayable headings to warrant a TOC. The TOC
|
|
30
|
+
* (`DocsToc`) only lists depth `minDepth`–`maxDepth` (2–3 by default), so the
|
|
31
|
+
* page H1 never counts; and a TOC of a single entry isn't useful, so require
|
|
32
|
+
* `min` (2) by default. Pages like a landing/welcome page — H1 + prose, no
|
|
33
|
+
* sub-sections — therefore get no "On this page".
|
|
34
|
+
*/
|
|
35
|
+
export function hasDisplayableToc(
|
|
36
|
+
headings: { depth: number }[],
|
|
37
|
+
opts: { minDepth?: number; maxDepth?: number; min?: number } = {},
|
|
38
|
+
): boolean {
|
|
39
|
+
const { minDepth = 2, maxDepth = 3, min = 2 } = opts;
|
|
40
|
+
let count = 0;
|
|
41
|
+
for (const h of headings) {
|
|
42
|
+
if (h.depth >= minDepth && h.depth <= maxDepth) count++;
|
|
43
|
+
if (count >= min) return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
28
48
|
export interface TocPlacementInput {
|
|
29
49
|
/** Page has at least one heading to list. */
|
|
30
50
|
hasHeadings: boolean;
|