@dogsbay/docs-layout 0.2.0-beta.143 → 0.2.0-beta.145
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 +16 -4
- package/src/VersionSwitcher.astro +1 -1
- package/src/switcher.ts +23 -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.145",
|
|
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.145",
|
|
35
|
+
"@dogsbay/site-files": "0.2.0-beta.145",
|
|
36
|
+
"@dogsbay/ui": "0.2.0-beta.145"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"happy-dom": "^20.10.6",
|
package/src/DocsLayout.astro
CHANGED
|
@@ -360,6 +360,10 @@ interface Props {
|
|
|
360
360
|
version?: string;
|
|
361
361
|
locale?: string;
|
|
362
362
|
originalSlug: string;
|
|
363
|
+
/** With a `products:` block: the version's URL segment (`latest`, or `""` at the product's root). */
|
|
364
|
+
versionPath?: string;
|
|
365
|
+
/** With a `products:` block: the product's other versions' URL segments. */
|
|
366
|
+
siblingVersionPaths?: string[];
|
|
363
367
|
};
|
|
364
368
|
/**
|
|
365
369
|
* Switcher data emitted by format-astro's `emitSwitcherMap`.
|
|
@@ -557,7 +561,15 @@ const {
|
|
|
557
561
|
|
|
558
562
|
// The version served at the site root (`path: ""`), if any: the sidebar
|
|
559
563
|
// keeps its pages by leaving out the other versions' folders.
|
|
560
|
-
|
|
564
|
+
// With a products: block the page carries its version's URL segment, which may
|
|
565
|
+
// differ from its id (`latest`); at the product's root (`""`) its menu leaves
|
|
566
|
+
// out the product's other versions' folders.
|
|
567
|
+
const navRootVersion = multiSource?.versionPath !== undefined
|
|
568
|
+
? multiSource.versionPath === ""
|
|
569
|
+
? { rootVersion: multiSource.version, versionSegments: multiSource.siblingVersionPaths ?? [] }
|
|
570
|
+
: {}
|
|
571
|
+
: rootVersionFilter(switcherMap?.versions);
|
|
572
|
+
const navVersion = multiSource?.versionPath ? multiSource.versionPath : multiSource?.version;
|
|
561
573
|
|
|
562
574
|
// Link icons — classified in CSS by href shape. `data-link-icons`
|
|
563
575
|
// lists which kinds are active; the glyphs ride in CSS custom props
|
|
@@ -1070,7 +1082,7 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
|
|
1070
1082
|
currentPath={currentPath}
|
|
1071
1083
|
basePath={basePath ?? ""}
|
|
1072
1084
|
namespace={multiSource?.namespace}
|
|
1073
|
-
version={
|
|
1085
|
+
version={navVersion}
|
|
1074
1086
|
locale={multiSource?.locale}
|
|
1075
1087
|
rootVersion={navRootVersion.rootVersion}
|
|
1076
1088
|
versionSegments={navRootVersion.versionSegments}
|
|
@@ -1086,7 +1098,7 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
|
|
1086
1098
|
items={filterNavByAxis(group.items, {
|
|
1087
1099
|
basePath: basePath ?? "/docs",
|
|
1088
1100
|
namespace: multiSource?.namespace,
|
|
1089
|
-
version:
|
|
1101
|
+
version: navVersion,
|
|
1090
1102
|
locale: multiSource?.locale,
|
|
1091
1103
|
...navRootVersion,
|
|
1092
1104
|
})}
|
|
@@ -1102,7 +1114,7 @@ const siteIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
|
|
|
1102
1114
|
items={filterNavByAxis(nav, {
|
|
1103
1115
|
basePath: basePath ?? "/docs",
|
|
1104
1116
|
namespace: multiSource?.namespace,
|
|
1105
|
-
version:
|
|
1117
|
+
version: navVersion,
|
|
1106
1118
|
locale: multiSource?.locale,
|
|
1107
1119
|
...navRootVersion,
|
|
1108
1120
|
})}
|
|
@@ -44,7 +44,7 @@ const currentLabel = currentRow?.entry.label ?? currentRow?.entry.id ?? "Version
|
|
|
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">
|
|
46
46
|
{rows.map((row) => {
|
|
47
|
-
const href = row.url ?? fallbackLandingUrl(basePath, row.entry.id, row.entry.root === true);
|
|
47
|
+
const href = row.url ?? row.entry.home ?? fallbackLandingUrl(basePath, row.entry.id, row.entry.root === true);
|
|
48
48
|
const isFallback = row.url === null && !row.isCurrent;
|
|
49
49
|
return (
|
|
50
50
|
<li>
|
package/src/switcher.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface AxisEntry {
|
|
|
26
26
|
* page is `<basePath>/`, and its per-page URLs come from the variants.
|
|
27
27
|
*/
|
|
28
28
|
root?: boolean;
|
|
29
|
+
/** With a `products:` block: the version's home URL, where the row goes when the page is not in it. */
|
|
30
|
+
home?: string;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
export interface SwitcherVariant {
|
|
@@ -38,6 +40,17 @@ export interface SwitcherMap {
|
|
|
38
40
|
versions: AxisEntry[];
|
|
39
41
|
locales: AxisEntry[];
|
|
40
42
|
byLogicalKey: Record<string, SwitcherVariant[]>;
|
|
43
|
+
/**
|
|
44
|
+
* With a `products:` block: each product's version rows per locale
|
|
45
|
+
* (`<product|_>/<locale|_>`), config order, hidden left out, with homes.
|
|
46
|
+
*/
|
|
47
|
+
productVersions?: Record<string, AxisEntry[]>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The current page's product version rows, when the site has a `products:` block. */
|
|
51
|
+
export function productVersionEntries(switcherMap: SwitcherMap, ms: MultiSourceMeta): AxisEntry[] | undefined {
|
|
52
|
+
if (!switcherMap.productVersions) return undefined;
|
|
53
|
+
return switcherMap.productVersions[`${ms.namespace ?? "_"}/${ms.locale ?? "_"}`] ?? [];
|
|
41
54
|
}
|
|
42
55
|
|
|
43
56
|
export interface MultiSourceMeta {
|
|
@@ -121,6 +134,15 @@ export function buildSwitcherRows(input: BuildRowsInput): SwitcherRow[] {
|
|
|
121
134
|
|
|
122
135
|
const variants = switcherMap.byLogicalKey[logicalKeyFor(multiSource)] ?? [];
|
|
123
136
|
|
|
137
|
+
// A products: block: the product's own rows, in config order (the shared model's switcher)
|
|
138
|
+
const productRows = axis === "version" ? productVersionEntries(switcherMap, multiSource) : undefined;
|
|
139
|
+
if (productRows) {
|
|
140
|
+
return productRows.map((entry) => {
|
|
141
|
+
const match = variants.find((v) => v.version === entry.id && (otherCurrent === undefined || v.locale === otherCurrent));
|
|
142
|
+
return { entry, url: match?.url ?? null, isCurrent: entry.id === currentId };
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
124
146
|
// On a MULTI-PRODUCT (namespace-active) site the declared version list
|
|
125
147
|
// is the UNION across products, but a page's variants are same-namespace
|
|
126
148
|
// (the logical key is namespaced). Scope the version switcher to the
|
|
@@ -204,7 +226,7 @@ export function shouldRenderSwitcher(
|
|
|
204
226
|
multiSource: MultiSourceMeta | undefined,
|
|
205
227
|
): boolean {
|
|
206
228
|
if (!multiSource) return false;
|
|
207
|
-
const entries = axis === "version" ? switcherMap.versions : switcherMap.locales;
|
|
229
|
+
const entries = (axis === "version" ? productVersionEntries(switcherMap, multiSource) : undefined) ?? (axis === "version" ? switcherMap.versions : switcherMap.locales);
|
|
208
230
|
if (entries.length < 2) return false;
|
|
209
231
|
const id = axis === "version" ? multiSource.version : multiSource.locale;
|
|
210
232
|
return id !== undefined;
|