@dogsbay/docs-layout 0.2.0-beta.147 → 0.2.0-beta.148
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 +4 -4
- package/src/DocsLayout.astro +18 -0
- package/src/ProductSwitcher.astro +63 -0
- package/src/VersionSwitcher.astro +22 -3
- package/src/switcher.ts +78 -1
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.148",
|
|
4
4
|
"description": "Standard documentation layout components for Dogsbay",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"./json-ld": "./src/json-ld.ts"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@dogsbay/primitives": "0.2.0-beta.
|
|
35
|
-
"@dogsbay/site-files": "0.2.0-beta.
|
|
36
|
-
"@dogsbay/ui": "0.2.0-beta.
|
|
34
|
+
"@dogsbay/primitives": "0.2.0-beta.148",
|
|
35
|
+
"@dogsbay/site-files": "0.2.0-beta.148",
|
|
36
|
+
"@dogsbay/ui": "0.2.0-beta.148"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"happy-dom": "^20.10.6",
|
package/src/DocsLayout.astro
CHANGED
|
@@ -44,8 +44,10 @@ import StatusBadge from "./StatusBadge.astro";
|
|
|
44
44
|
import TypeBadge from "./TypeBadge.astro";
|
|
45
45
|
import PageActions from "./PageActions.astro";
|
|
46
46
|
import VersionSwitcher from "./VersionSwitcher.astro";
|
|
47
|
+
import ProductSwitcher from "./ProductSwitcher.astro";
|
|
47
48
|
import LocaleSwitcher from "./LocaleSwitcher.astro";
|
|
48
49
|
import { filterNavByAxis, rootVersionFilter } from "./nav-filter.js";
|
|
50
|
+
import { versionBadge } from "./switcher.js";
|
|
49
51
|
import type { LlmProviderName } from "./llm-actions.js";
|
|
50
52
|
import { jsonLdTypeFor, normalizeCustomJsonLd, buildArticleJsonLd, buildWebSiteJsonLd } from "./json-ld.js";
|
|
51
53
|
import { resolveTagKeywords } from "./tag-list-data.js";
|
|
@@ -338,6 +340,12 @@ interface Props {
|
|
|
338
340
|
* opt in. See plans/auto-lede.md.
|
|
339
341
|
*/
|
|
340
342
|
autoH1?: boolean;
|
|
343
|
+
/**
|
|
344
|
+
* The version badge's wording on a page whose version has `badge: true`
|
|
345
|
+
* (`{label}` is the version's label). Default "Version: {label}", as
|
|
346
|
+
* dogsbay-ssg's English `versionBadge` string.
|
|
347
|
+
*/
|
|
348
|
+
versionBadgeWording?: string;
|
|
341
349
|
/**
|
|
342
350
|
* When `true`, render `<p>{description}</p>` below the auto H1
|
|
343
351
|
* (or above the meta strip when there's no H1) — used when the
|
|
@@ -541,6 +549,7 @@ const {
|
|
|
541
549
|
taxonomyIndexPaths,
|
|
542
550
|
taxonomyDisplay,
|
|
543
551
|
autoH1,
|
|
552
|
+
versionBadgeWording,
|
|
544
553
|
autoLede,
|
|
545
554
|
llmActions,
|
|
546
555
|
customJsonLd,
|
|
@@ -569,6 +578,8 @@ const navRootVersion = multiSource?.versionPath !== undefined
|
|
|
569
578
|
? { rootVersion: multiSource.version, versionSegments: multiSource.siblingVersionPaths ?? [] }
|
|
570
579
|
: {}
|
|
571
580
|
: rootVersionFilter(switcherMap?.versions);
|
|
581
|
+
// "Version: 3.33" above the title, on a version with `badge: true` (Docusaurus's version badge)
|
|
582
|
+
const badgeText = versionBadge(switcherMap as never, multiSource as never, versionBadgeWording);
|
|
572
583
|
const navVersion = multiSource?.versionPath ? multiSource.versionPath : multiSource?.version;
|
|
573
584
|
|
|
574
585
|
// Link icons — classified in CSS by href shape. `data-link-icons`
|
|
@@ -1152,6 +1163,8 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
|
|
1152
1163
|
</div>
|
|
1153
1164
|
</details>
|
|
1154
1165
|
)}
|
|
1166
|
+
{/* Products before languages and versions, as dogsbay-ssg; also on pages outside every product */}
|
|
1167
|
+
{switcherMap && <ProductSwitcher switcherMap={switcherMap} multiSource={multiSource} />}
|
|
1155
1168
|
{switcherMap && multiSource && (
|
|
1156
1169
|
<LocaleSwitcher
|
|
1157
1170
|
switcherMap={switcherMap}
|
|
@@ -1307,6 +1320,11 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
|
|
1307
1320
|
gets context (title, summary) before classification
|
|
1308
1321
|
(chips), then content.
|
|
1309
1322
|
*/}
|
|
1323
|
+
{badgeText && (
|
|
1324
|
+
<div class="not-prose mb-3" data-version-badge>
|
|
1325
|
+
<span class="inline-flex items-center rounded-md border border-border bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground">{badgeText}</span>
|
|
1326
|
+
</div>
|
|
1327
|
+
)}
|
|
1310
1328
|
{autoH1 && (
|
|
1311
1329
|
<h1 class="text-3xl font-bold tracking-tight mb-2">
|
|
1312
1330
|
{title}
|
|
@@ -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 rounded-md border border-border px-3 py-1.5 text-sm hover:bg-accent">
|
|
27
|
+
{menu.current && <span class="sr-only">{placeholder}: </span>}
|
|
28
|
+
<span class:list={["font-medium", !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>
|
|
@@ -12,7 +12,9 @@ import {
|
|
|
12
12
|
type MultiSourceMeta,
|
|
13
13
|
buildSwitcherRows,
|
|
14
14
|
fallbackLandingUrl,
|
|
15
|
+
limitRows,
|
|
15
16
|
shouldRenderSwitcher,
|
|
17
|
+
versionMenuFor,
|
|
16
18
|
} from "./switcher.js";
|
|
17
19
|
|
|
18
20
|
interface Props {
|
|
@@ -23,9 +25,13 @@ interface Props {
|
|
|
23
25
|
|
|
24
26
|
const { switcherMap, multiSource, basePath = "/docs" } = Astro.props;
|
|
25
27
|
const visible = shouldRenderSwitcher("version", switcherMap, multiSource);
|
|
28
|
+
// Whether the menu shows is decided before `limit` (versionMenu): then the
|
|
29
|
+
// first N rows, plus the page's own, and the menu's links after them.
|
|
30
|
+
const menu = visible ? versionMenuFor(switcherMap, multiSource!) : undefined;
|
|
26
31
|
const rows = visible
|
|
27
|
-
? buildSwitcherRows({ axis: "version", switcherMap, multiSource: multiSource! })
|
|
32
|
+
? limitRows(buildSwitcherRows({ axis: "version", switcherMap, multiSource: multiSource! }), menu?.limit)
|
|
28
33
|
: [];
|
|
34
|
+
const links = menu?.links ?? [];
|
|
29
35
|
const currentRow = rows.find((r) => r.isCurrent);
|
|
30
36
|
const currentLabel = currentRow?.entry.label ?? currentRow?.entry.id ?? "Version";
|
|
31
37
|
---
|
|
@@ -40,9 +46,10 @@ const currentLabel = currentRow?.entry.label ?? currentRow?.entry.id ?? "Version
|
|
|
40
46
|
{currentRow?.entry.prerelease && (
|
|
41
47
|
<span class="ml-1 rounded bg-muted px-1 text-[10px] uppercase text-muted-foreground">Pre</span>
|
|
42
48
|
)}
|
|
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>
|
|
49
|
+
<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>
|
|
44
50
|
</summary>
|
|
45
|
-
<
|
|
51
|
+
<div class="absolute right-0 z-50 mt-1 min-w-[10rem] rounded-md border border-border bg-popover p-1 text-sm shadow-md">
|
|
52
|
+
<ul>
|
|
46
53
|
{rows.map((row) => {
|
|
47
54
|
const href = row.url ?? row.entry.home ?? fallbackLandingUrl(basePath, row.entry.id, row.entry.root === true);
|
|
48
55
|
const isFallback = row.url === null && !row.isCurrent;
|
|
@@ -76,6 +83,18 @@ const currentLabel = currentRow?.entry.label ?? currentRow?.entry.id ?? "Version
|
|
|
76
83
|
);
|
|
77
84
|
})}
|
|
78
85
|
</ul>
|
|
86
|
+
{links.length > 0 && (
|
|
87
|
+
<ul class="mt-1 border-t border-border pt-1" data-version-menu-links>
|
|
88
|
+
{links.map((link) => (
|
|
89
|
+
<li>
|
|
90
|
+
<a href={link.href} class="flex items-center gap-2 rounded-sm px-2 py-1.5 text-foreground no-underline hover:bg-accent">
|
|
91
|
+
{link.label}
|
|
92
|
+
</a>
|
|
93
|
+
</li>
|
|
94
|
+
))}
|
|
95
|
+
</ul>
|
|
96
|
+
)}
|
|
97
|
+
</div>
|
|
79
98
|
</details>
|
|
80
99
|
)}
|
|
81
100
|
|
package/src/switcher.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* `format-astro/src/project.ts` (the emitter side).
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import { limitVersionRows } from "@dogsbay/site-files";
|
|
11
|
+
|
|
10
12
|
export interface AxisEntry {
|
|
11
13
|
id: string;
|
|
12
14
|
label?: string;
|
|
@@ -28,6 +30,14 @@ export interface AxisEntry {
|
|
|
28
30
|
root?: boolean;
|
|
29
31
|
/** With a `products:` block: the version's home URL, where the row goes when the page is not in it. */
|
|
30
32
|
home?: string;
|
|
33
|
+
/** "Version: <label>" above each page's title (version axis only). */
|
|
34
|
+
badge?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The version menu's links (hrefs as served) and limit, from `versionMenu:` (@dogsbay/site-files version-menu.ts). */
|
|
38
|
+
export interface VersionMenuData {
|
|
39
|
+
links: Array<{ label: string; href: string }>;
|
|
40
|
+
limit?: number;
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
export interface SwitcherVariant {
|
|
@@ -45,6 +55,39 @@ export interface SwitcherMap {
|
|
|
45
55
|
* (`<product|_>/<locale|_>`), config order, hidden left out, with homes.
|
|
46
56
|
*/
|
|
47
57
|
productVersions?: Record<string, AxisEntry[]>;
|
|
58
|
+
/**
|
|
59
|
+
* With a `products:` block and two or more products: the product menu per
|
|
60
|
+
* locale (`<locale|_>`), block order, each entry the product's home.
|
|
61
|
+
*/
|
|
62
|
+
products?: Record<string, ProductMenuEntry[]>;
|
|
63
|
+
/** Per product name (`_`: the site-wide versions), the version menu's links and limit. */
|
|
64
|
+
versionMenu?: Record<string, VersionMenuData>;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface ProductMenuEntry {
|
|
68
|
+
name: string;
|
|
69
|
+
label: string;
|
|
70
|
+
home: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface ProductMenu {
|
|
74
|
+
/** The page's product, or undefined on a page outside every product (the menu reads "Product"). */
|
|
75
|
+
current?: ProductMenuEntry;
|
|
76
|
+
entries: ProductMenuEntry[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The product menu for a page (the same rules as dogsbay-ssg's): only with two
|
|
81
|
+
* or more products, in the page's locale (else the site's first), each entry
|
|
82
|
+
* going to that product's home — products do not share pages, so the current
|
|
83
|
+
* page is never looked up. A page outside every product has no current entry.
|
|
84
|
+
*/
|
|
85
|
+
export function productMenu(switcherMap: SwitcherMap, ms?: Pick<MultiSourceMeta, "namespace" | "locale">): ProductMenu | undefined {
|
|
86
|
+
const byLocale = switcherMap.products;
|
|
87
|
+
if (!byLocale) return undefined;
|
|
88
|
+
const entries = byLocale[ms?.locale ?? "_"] ?? Object.values(byLocale)[0];
|
|
89
|
+
if (!entries || entries.length < 2) return undefined;
|
|
90
|
+
return { current: entries.find((e) => e.name === ms?.namespace), entries };
|
|
48
91
|
}
|
|
49
92
|
|
|
50
93
|
/** The current page's product version rows, when the site has a `products:` block. */
|
|
@@ -227,7 +270,8 @@ export function shouldRenderSwitcher(
|
|
|
227
270
|
): boolean {
|
|
228
271
|
if (!multiSource) return false;
|
|
229
272
|
const entries = (axis === "version" ? productVersionEntries(switcherMap, multiSource) : undefined) ?? (axis === "version" ? switcherMap.versions : switcherMap.locales);
|
|
230
|
-
|
|
273
|
+
// Two or more versions a reader can pick (a hidden one is the number an alias serves), as dogsbay-ssg decides it
|
|
274
|
+
if (entries.filter((e) => !e.hidden).length < 2) return false;
|
|
231
275
|
const id = axis === "version" ? multiSource.version : multiSource.locale;
|
|
232
276
|
return id !== undefined;
|
|
233
277
|
}
|
|
@@ -247,3 +291,36 @@ export function fallbackLandingUrl(
|
|
|
247
291
|
const trimmed = basePath.replace(/\/$/, "");
|
|
248
292
|
return atRoot ? `${trimmed}/` : `${trimmed}/${axisEntryId}/`;
|
|
249
293
|
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* The page's version menu extras: its product's (with a `products:` block),
|
|
297
|
+
* else the site's. Only for a menu that is shown, so its links come with it.
|
|
298
|
+
*/
|
|
299
|
+
export function versionMenuFor(switcherMap: SwitcherMap, ms: Pick<MultiSourceMeta, "namespace">): VersionMenuData | undefined {
|
|
300
|
+
const menus = switcherMap.versionMenu;
|
|
301
|
+
if (!menus) return undefined;
|
|
302
|
+
return switcherMap.productVersions ? menus[ms.namespace ?? "_"] : menus._;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* The menu's rows under `limit`: whether it shows is decided before (two or
|
|
307
|
+
* more versions), then the first `limit` rows are kept, plus the page's own.
|
|
308
|
+
*/
|
|
309
|
+
export function limitRows(rows: SwitcherRow[], limit: number | undefined): SwitcherRow[] {
|
|
310
|
+
return limitVersionRows(rows, limit, (r) => r.isCurrent);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* "Version: <label>" for a page whose version has `badge: true`, else
|
|
315
|
+
* undefined. The label is the one the version menu shows.
|
|
316
|
+
*/
|
|
317
|
+
export function versionBadge(switcherMap: SwitcherMap | undefined, ms: MultiSourceMeta | undefined, wording = "Version: {label}"): string | undefined {
|
|
318
|
+
if (!switcherMap || !ms?.version) return undefined;
|
|
319
|
+
const entries = productVersionEntries(switcherMap, ms) ?? switcherMap.versions;
|
|
320
|
+
const entry = entries.find((e) => e.id === ms.version);
|
|
321
|
+
if (!entry?.badge) return undefined;
|
|
322
|
+
// The `latest` alias stands for the hidden number it serves (migrate-docusaurus --latest-alias)
|
|
323
|
+
const target = entry.id === "latest" ? [...entries].sort((a, b) => compareVersionIds(b.id, a.id)).find((e) => e.hidden && /\d/.test(e.id)) : undefined;
|
|
324
|
+
const shown = target ?? entry;
|
|
325
|
+
return wording.split("{label}").join(shown.label ?? shown.id);
|
|
326
|
+
}
|