@dogsbay/docs-layout 0.2.0-beta.93 → 0.2.0-beta.95
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 +6 -5
- package/src/BlogIndex.astro +179 -0
- package/src/DocsFooter.astro +12 -2
- package/src/DocsLayout.astro +277 -4
- package/src/DocsNavClient.astro +21 -3
- package/src/SearchDialog.astro +29 -1
- package/src/VersionSwitcher.astro +6 -0
- package/src/docs-nav-client.ts +81 -2
- package/src/link-icons.ts +54 -0
- package/src/markdown-negotiation.ts +38 -2
- package/src/nav-filter.ts +42 -129
- package/src/switcher.ts +83 -2
package/src/switcher.ts
CHANGED
|
@@ -11,6 +11,14 @@ export interface AxisEntry {
|
|
|
11
11
|
id: string;
|
|
12
12
|
label?: string;
|
|
13
13
|
eol?: boolean;
|
|
14
|
+
/** Pre-release mark (version axis only) — the moving next/beta head. */
|
|
15
|
+
prerelease?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Served but kept OFF the switcher (version axis only). Marks the number
|
|
18
|
+
* a `latest` alias points at, so the dropdown shows one "3.32 (latest)"
|
|
19
|
+
* row instead of both "latest" and "3.32".
|
|
20
|
+
*/
|
|
21
|
+
hidden?: boolean;
|
|
14
22
|
default?: boolean;
|
|
15
23
|
}
|
|
16
24
|
|
|
@@ -73,9 +81,32 @@ export interface BuildRowsInput {
|
|
|
73
81
|
multiSource: MultiSourceMeta;
|
|
74
82
|
}
|
|
75
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Order two version ids. Compares numeric components left-to-right
|
|
86
|
+
* (`3.32` > `3.31`, `3.23-2` > `3.23-1`); a non-numeric alias (`latest`,
|
|
87
|
+
* `next`) sorts ABOVE any numbered version so descending order puts it
|
|
88
|
+
* first. When NEITHER id has any digits — a non-semver / codename scheme
|
|
89
|
+
* (`Boron`, `Argon`) — returns 0 so the sort is a no-op and the author's
|
|
90
|
+
* DECLARED order is preserved (JS sort is stable), rather than silently
|
|
91
|
+
* alphabetising and putting the newest release at the bottom.
|
|
92
|
+
*/
|
|
93
|
+
export function compareVersionIds(a: string, b: string): number {
|
|
94
|
+
const na = (a.match(/\d+/g) ?? []).map(Number);
|
|
95
|
+
const nb = (b.match(/\d+/g) ?? []).map(Number);
|
|
96
|
+
if (na.length === 0 && nb.length === 0) return 0; // codenames → keep declared order
|
|
97
|
+
if (na.length === 0) return 1; // alias > number
|
|
98
|
+
if (nb.length === 0) return -1;
|
|
99
|
+
const len = Math.max(na.length, nb.length);
|
|
100
|
+
for (let i = 0; i < len; i++) {
|
|
101
|
+
const d = (na[i] ?? 0) - (nb[i] ?? 0);
|
|
102
|
+
if (d !== 0) return d;
|
|
103
|
+
}
|
|
104
|
+
return a.localeCompare(b);
|
|
105
|
+
}
|
|
106
|
+
|
|
76
107
|
export function buildSwitcherRows(input: BuildRowsInput): SwitcherRow[] {
|
|
77
108
|
const { axis, switcherMap, multiSource } = input;
|
|
78
|
-
const
|
|
109
|
+
const allEntries = axis === "version" ? switcherMap.versions : switcherMap.locales;
|
|
79
110
|
const currentId =
|
|
80
111
|
axis === "version" ? multiSource.version : multiSource.locale;
|
|
81
112
|
const otherAxis: SwitcherAxis = axis === "version" ? "locale" : "version";
|
|
@@ -84,6 +115,56 @@ export function buildSwitcherRows(input: BuildRowsInput): SwitcherRow[] {
|
|
|
84
115
|
|
|
85
116
|
const variants = switcherMap.byLogicalKey[logicalKeyFor(multiSource)] ?? [];
|
|
86
117
|
|
|
118
|
+
// On a MULTI-PRODUCT (namespace-active) site the declared version list
|
|
119
|
+
// is the UNION across products, but a page's variants are same-namespace
|
|
120
|
+
// (the logical key is namespaced). Scope the version switcher to the
|
|
121
|
+
// versions this page's product actually has, so a Calico page never
|
|
122
|
+
// offers a Calico-Enterprise version. Single-product sites (no
|
|
123
|
+
// namespace) keep the full declared list, with fallbacks for pages
|
|
124
|
+
// missing in some version.
|
|
125
|
+
let entries = allEntries;
|
|
126
|
+
if (axis === "version" && multiSource.namespace !== undefined) {
|
|
127
|
+
const available = new Set(
|
|
128
|
+
variants.map((v) => v.version).filter((v): v is string => v !== undefined),
|
|
129
|
+
);
|
|
130
|
+
entries = allEntries.filter((e) => available.has(e.id) || e.id === currentId);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// The version dropdown always reads newest → oldest (3.32, 3.31, …),
|
|
134
|
+
// regardless of the declared order. Aliases (e.g. "latest") that don't
|
|
135
|
+
// parse as versions sort to the top, ahead of the numbers.
|
|
136
|
+
//
|
|
137
|
+
// `latest` alias + its target: a version marked `hidden` is the number
|
|
138
|
+
// the `latest` alias points at (Docusaurus's lastVersion). Show ONE row
|
|
139
|
+
// "3.32 (latest)" (linking to /latest/), derive its label from the hidden
|
|
140
|
+
// sibling, and drop hidden rows from the dropdown.
|
|
141
|
+
//
|
|
142
|
+
// The hidden number is DECLARED but NOT SERVED: `migrate-docusaurus
|
|
143
|
+
// --latest-alias` emits one source for the newest branch, at `latest`.
|
|
144
|
+
// That mirrors the source, where `versions: { "3.32": { path: "latest" } }`
|
|
145
|
+
// REPLACES the segment — docs.tigera.io has /calico/latest/ and no
|
|
146
|
+
// /calico/3.32/. Serving both invented a URL tree the source never had
|
|
147
|
+
// and duplicated every page of the newest release (338 on Calico) with
|
|
148
|
+
// no canonical. So the hidden entry is label-only metadata.
|
|
149
|
+
//
|
|
150
|
+
// `currentFoldedIntoLatest` still matters for a corpus that DOES serve
|
|
151
|
+
// the number (a hand-written config may), so a reader on `/3.32/…` has
|
|
152
|
+
// the merged `latest` row highlighted rather than no row at all. No
|
|
153
|
+
// `hidden` sibling → no merge.
|
|
154
|
+
let currentFoldedIntoLatest = false;
|
|
155
|
+
if (axis === "version") {
|
|
156
|
+
entries = [...entries].sort((a, b) => compareVersionIds(b.id, a.id));
|
|
157
|
+
const hiddenTarget = entries.find((e) => e.hidden && /\d/.test(e.id));
|
|
158
|
+
currentFoldedIntoLatest = hiddenTarget?.id === currentId;
|
|
159
|
+
entries = entries
|
|
160
|
+
.filter((e) => !e.hidden)
|
|
161
|
+
.map((e) =>
|
|
162
|
+
e.id === "latest" && hiddenTarget
|
|
163
|
+
? { ...e, label: `${hiddenTarget.label ?? hiddenTarget.id} (latest)` }
|
|
164
|
+
: e,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
87
168
|
return entries.map((entry) => {
|
|
88
169
|
const match = variants.find((v) => {
|
|
89
170
|
// Match on this axis.
|
|
@@ -98,7 +179,7 @@ export function buildSwitcherRows(input: BuildRowsInput): SwitcherRow[] {
|
|
|
98
179
|
return {
|
|
99
180
|
entry,
|
|
100
181
|
url: match?.url ?? null,
|
|
101
|
-
isCurrent: entry.id === currentId,
|
|
182
|
+
isCurrent: entry.id === currentId || (entry.id === "latest" && currentFoldedIntoLatest),
|
|
102
183
|
};
|
|
103
184
|
});
|
|
104
185
|
}
|