@writedocs/generator 0.10.1 → 0.10.3

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": "@writedocs/generator",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "description": "Static site generator for docs — a writedocs.json + MDX folder in, a static site out.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -426,7 +426,7 @@ const securityJson = JSON.stringify(op?.security ?? []);
426
426
  .wd-api-panel {
427
427
  position: sticky;
428
428
  top: var(--wd-topbar-offset, 5rem);
429
- padding: 1.5rem 1.5rem 1.5rem 1rem;
429
+ padding: 1.5rem 0 1.5rem 1rem;
430
430
  max-height: calc(100vh - var(--wd-topbar-offset, 5rem));
431
431
  overflow-y: auto;
432
432
  display: flex;
@@ -31,7 +31,7 @@
31
31
  // comment for the fuller rationale.
32
32
  import { isExternalHref, type DocsConfig, type Selector, type GlobalDropdownView } from '../../lib/config';
33
33
  import AppIcon from '../../components/AppIcon.astro';
34
- import { hasMobileMenu } from '../../lib/selector-placement.js';
34
+ import { hasMobileMenu, currentOption } from '../../lib/selector-placement.js';
35
35
  import '../styles/dropdown.css';
36
36
  import '../styles/topbar.css';
37
37
  import '../styles/mobile-menu.css';
@@ -101,7 +101,28 @@ const showMenu = hasMobileMenu({ sidebar: showSidebarCol, selectors, globalDropd
101
101
  {(selectors.some((sel) => !sel.hidden) || globalDropdowns.length > 0) && (
102
102
  <div class="wd-mobile-menu-selectors">
103
103
  {selectors.filter((sel) => !sel.hidden).map((sel) => {
104
- const current = sel.options.find((o) => o.active) ?? sel.options[0];
104
+ // The level under an item whose own page this is, with nothing
105
+ // chosen yet (landingSelectors() in lib/config.ts): its options
106
+ // as an open list - a closed one would repeat the item's name,
107
+ // already on the level above.
108
+ if (sel.placeholder && !sel.options.some((opt) => opt.active)) {
109
+ return (
110
+ <nav class="wd-mobile-menu-choices" aria-label={sel.placeholder.label}>
111
+ {sel.options.map((opt) => (
112
+ <a
113
+ href={opt.href}
114
+ target={isExternalHref(opt.href) ? '_blank' : undefined}
115
+ rel={isExternalHref(opt.href) ? 'noopener noreferrer' : undefined}
116
+ >
117
+ <AppIcon icon={opt.icon} class="wd-tab-icon" />
118
+ <span class="wd-mobile-accordion-option-label">{opt.label}</span>
119
+ {opt.tag && <span class="wd-selector-tag">{opt.tag}</span>}
120
+ </a>
121
+ ))}
122
+ </nav>
123
+ );
124
+ }
125
+ const current = currentOption(sel);
105
126
  return (
106
127
  <details class="wd-mobile-accordion" name="wd-mobile-accordion">
107
128
  <summary class="wd-mobile-accordion-trigger">
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  import { isExternalHref, type NavTreeNode, type Selector } from "../../lib/config";
3
3
  import NavTree from "./NavTree.astro";
4
+ import { currentOption } from "../../lib/selector-placement.js";
4
5
  import AppIcon from "../../components/AppIcon.astro";
5
6
  // Two colorways of the same "Powered by writedocs" mark, not a
6
7
  // theme-matched pair in the wd-logo-light/wd-logo-dark sense (that
@@ -42,7 +43,7 @@ const { navTree, hrefForSlug, currentSlug, switchers = [] } = Astro.props as Pro
42
43
 
43
44
  <nav class="wd-sidebar">
44
45
  {switchers.map((sel) => {
45
- const current = sel.options.find((o) => o.active) ?? sel.options[0];
46
+ const current = currentOption(sel);
46
47
  return (
47
48
  <div class="wd-dropdown wd-sidebar-switcher" data-selector-kind={sel.kind}>
48
49
  <button type="button" class="wd-dropdown-trigger wd-sidebar-switcher-trigger" aria-expanded="false">
@@ -13,7 +13,7 @@
13
13
  // comment for the fuller rationale.
14
14
  import { isExternalHref, type DocsConfig, type Selector, type GlobalDropdownView } from '../../lib/config';
15
15
  import AppIcon from '../../components/AppIcon.astro';
16
- import { selectorPlacements, hasMobileMenu } from '../../lib/selector-placement.js';
16
+ import { selectorPlacements, hasMobileMenu, currentOption } from '../../lib/selector-placement.js';
17
17
  import '../styles/dropdown.css';
18
18
  import '../styles/topbar.css';
19
19
 
@@ -105,7 +105,7 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
105
105
  // trigger shows the *current* option, the menu lists the
106
106
  // alternatives - unlike tabs, where every option is its own
107
107
  // always-visible pill in the row below.
108
- const current = sel.options.find((o) => o.active) ?? sel.options[0];
108
+ const current = currentOption(sel);
109
109
  return (
110
110
  <div class="wd-dropdown" data-selector-kind={sel.kind}>
111
111
  <button type="button" class="wd-dropdown-trigger wd-switcher-trigger" aria-expanded="false">
@@ -249,17 +249,66 @@ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length
249
249
  </button>
250
250
  <div class="wd-dropdown-menu">
251
251
  <div class="wd-dropdown-menu-panel">
252
- {opt.dropdown.map((d) => (
253
- <a
254
- href={d.href}
255
- class={d.active ? 'active' : ''} aria-current={d.active ? 'true' : undefined}
256
- target={isExternalHref(d.href) ? '_blank' : undefined}
257
- rel={isExternalHref(d.href) ? 'noopener noreferrer' : undefined}
258
- >
259
- <AppIcon icon={d.icon} class="wd-tab-icon" />
260
- {d.label}
261
- </a>
262
- ))}
252
+ {opt.dropdown.map((d) =>
253
+ d.submenu ? (
254
+ // An entry holding dropdowns of its own: they open in
255
+ // a flyout beside it, on hover, or on a click on the
256
+ // arrow - or on the entry itself when it has no page
257
+ // of its own to open (src/scripts/dropdowns.ts).
258
+ <div class={`wd-submenu ${d.active ? 'wd-submenu-active' : ''}`}>
259
+ <div class="wd-submenu-row">
260
+ {d.pageHref ? (
261
+ <a href={d.pageHref} class={`wd-submenu-entry ${d.active ? 'active' : ''}`} aria-current={d.active ? 'true' : undefined}>
262
+ <AppIcon icon={d.icon} class="wd-tab-icon" />
263
+ <span class="wd-submenu-label">{d.label}</span>
264
+ </a>
265
+ ) : null}
266
+ <button
267
+ type="button"
268
+ class={`wd-submenu-toggle ${d.pageHref ? 'wd-submenu-arrow' : `wd-submenu-entry ${d.active ? 'active' : ''}`}`}
269
+ aria-expanded="false"
270
+ aria-label={d.pageHref ? `${d.label} - more` : undefined}
271
+ >
272
+ {!d.pageHref && <AppIcon icon={d.icon} class="wd-tab-icon" />}
273
+ {!d.pageHref && <span class="wd-submenu-label">{d.label}</span>}
274
+ <svg class="wd-submenu-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
275
+ <path d="M3.5 2L6.5 5L3.5 8" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
276
+ </svg>
277
+ </button>
278
+ </div>
279
+ <div class="wd-submenu-panel">
280
+ <div class="wd-dropdown-menu-panel">
281
+ {d.pageHref ? (
282
+ <a href={d.pageHref} class="wd-submenu-heading">{d.label}</a>
283
+ ) : (
284
+ <span class="wd-submenu-heading">{d.label}</span>
285
+ )}
286
+ {d.submenu.map((sub) => (
287
+ <a
288
+ href={sub.href}
289
+ class={sub.active ? 'active' : ''} aria-current={sub.active ? 'true' : undefined}
290
+ target={isExternalHref(sub.href) ? '_blank' : undefined}
291
+ rel={isExternalHref(sub.href) ? 'noopener noreferrer' : undefined}
292
+ >
293
+ <AppIcon icon={sub.icon} class="wd-tab-icon" />
294
+ {sub.label}
295
+ </a>
296
+ ))}
297
+ </div>
298
+ </div>
299
+ </div>
300
+ ) : (
301
+ <a
302
+ href={d.href}
303
+ class={d.active ? 'active' : ''} aria-current={d.active ? 'true' : undefined}
304
+ target={isExternalHref(d.href) ? '_blank' : undefined}
305
+ rel={isExternalHref(d.href) ? 'noopener noreferrer' : undefined}
306
+ >
307
+ <AppIcon icon={d.icon} class="wd-tab-icon" />
308
+ {d.label}
309
+ </a>
310
+ )
311
+ )}
263
312
  </div>
264
313
  </div>
265
314
  </div>
@@ -99,6 +99,110 @@
99
99
  background: color-mix(in srgb, var(--wd-primary) 10%, transparent);
100
100
  }
101
101
 
102
+ /* A tab menu's entry that holds dropdowns of its own (TopBar.astro): a row -
103
+ the entry, a link to its page when it has one, and an arrow button - with
104
+ a flyout beside it. The flyout opens on hover (below), or on a click/key
105
+ (.open, src/scripts/dropdowns.ts); near the right end of the tab row it
106
+ opens to the left instead (.wd-submenu-left, src/scripts/tabs-strip.ts). */
107
+ .wd-submenu {
108
+ position: relative;
109
+ }
110
+ .wd-submenu-row {
111
+ display: flex;
112
+ align-items: stretch;
113
+ border-radius: 0.35rem;
114
+ }
115
+ .wd-submenu-row:hover,
116
+ .wd-submenu.open > .wd-submenu-row {
117
+ background: var(--wd-surface);
118
+ }
119
+ .wd-submenu-active > .wd-submenu-row {
120
+ background: color-mix(in srgb, var(--wd-primary) 10%, transparent);
121
+ }
122
+ .wd-dropdown-menu .wd-submenu-entry {
123
+ flex: 1;
124
+ min-width: 0;
125
+ display: flex;
126
+ align-items: center;
127
+ gap: 0.5rem;
128
+ padding: 0.45rem 0.6rem;
129
+ border: none;
130
+ border-radius: 0.35rem;
131
+ background: none;
132
+ font: inherit;
133
+ font-size: 0.88rem;
134
+ color: var(--wd-text);
135
+ text-align: left;
136
+ text-decoration: none;
137
+ cursor: pointer;
138
+ }
139
+ .wd-dropdown-menu .wd-submenu-entry:hover,
140
+ .wd-dropdown-menu .wd-submenu-entry.active {
141
+ background: none;
142
+ }
143
+ .wd-dropdown-menu .wd-submenu-entry.active {
144
+ color: var(--wd-primary);
145
+ }
146
+ .wd-submenu-label {
147
+ flex: 1;
148
+ min-width: 0;
149
+ }
150
+ .wd-submenu-arrow {
151
+ display: flex;
152
+ align-items: center;
153
+ padding: 0 0.55rem;
154
+ border: none;
155
+ border-radius: 0.35rem;
156
+ background: none;
157
+ color: var(--wd-text-muted);
158
+ cursor: pointer;
159
+ }
160
+ .wd-submenu-arrow:hover {
161
+ color: var(--wd-text);
162
+ }
163
+ .wd-submenu-caret {
164
+ flex-shrink: 0;
165
+ color: var(--wd-text-muted);
166
+ }
167
+ /* Level with the row it opens from: up by the panel's own padding and
168
+ border. The gap is padding, not an offset, so the pointer crossing it
169
+ stays on the flyout - the same reason as .wd-dropdown-menu's. */
170
+ .wd-submenu-panel {
171
+ display: none;
172
+ position: absolute;
173
+ top: calc(-0.4rem - 1px);
174
+ left: 100%;
175
+ padding-left: 0.45rem;
176
+ z-index: 21;
177
+ }
178
+ .wd-submenu-panel .wd-dropdown-menu-panel {
179
+ min-width: 200px;
180
+ }
181
+ .wd-submenu:hover > .wd-submenu-panel,
182
+ .wd-submenu.open > .wd-submenu-panel {
183
+ display: block;
184
+ }
185
+ .wd-submenu-left > .wd-submenu-panel {
186
+ left: auto;
187
+ right: 100%;
188
+ padding-left: 0;
189
+ padding-right: 0.45rem;
190
+ }
191
+ .wd-dropdown-menu .wd-submenu-heading {
192
+ display: block;
193
+ padding: 0.45rem 0.6rem 0.35rem;
194
+ font-size: 0.72rem;
195
+ font-weight: 600;
196
+ letter-spacing: 0.04em;
197
+ text-transform: uppercase;
198
+ color: var(--wd-primary);
199
+ text-decoration: none;
200
+ }
201
+ .wd-dropdown-menu a.wd-submenu-heading:hover {
202
+ background: none;
203
+ text-decoration: underline;
204
+ }
205
+
102
206
  /* .wd-tab-icon is shared by AppIcon's two render modes: a real <svg>
103
207
  (astro-icon, sized to the surrounding text) or a <span> (literal
104
208
  emoji/text, sized by inherited font-size alone). Used by every dropdown
@@ -258,6 +258,27 @@
258
258
  font-size: 0.9rem;
259
259
  }
260
260
  .wd-mobile-menu-link:hover { background: var(--wd-surface); }
261
+ /* An item's options with none chosen (MobileMenu.astro) - an open list, in
262
+ one box like a closed level's row. */
263
+ .wd-mobile-menu-choices {
264
+ display: flex;
265
+ flex-direction: column;
266
+ gap: 0.15rem;
267
+ padding: 0.3rem;
268
+ border: 1px solid var(--wd-border);
269
+ border-radius: 0.5rem;
270
+ }
271
+ .wd-mobile-menu-choices a {
272
+ display: flex;
273
+ align-items: center;
274
+ gap: 0.5rem;
275
+ padding: 0.5rem 0.45rem;
276
+ border-radius: 0.4rem;
277
+ text-decoration: none;
278
+ color: var(--wd-navbar-foreground);
279
+ font-size: 0.9rem;
280
+ }
281
+ .wd-mobile-menu-choices a:hover { background: var(--wd-surface); }
261
282
  /* The sidebar copy living in here needs none of .wd-sidebar-col's own
262
283
  column sizing (width/border/min-height) - it's just flowing content
263
284
  inside an already-padded, already-scrollable panel. */
@@ -26,7 +26,7 @@
26
26
  .wd-topbar-inner {
27
27
  max-width: 1440px;
28
28
  margin: 0 auto;
29
- padding: 0.75rem 0;
29
+ padding: 0.75rem 0 0.25rem;
30
30
  display: flex;
31
31
  align-items: center;
32
32
  gap: 1rem;
@@ -33,7 +33,7 @@ const navItemSchema = z.lazy(
33
33
  () => z.union([navPageSchema, navGroupSchema, navLinkSchema])
34
34
  );
35
35
  function withChildren(ownFields) {
36
- const base = { ...ownFields, hidden: z.boolean().optional(), searchPublic: z.boolean().optional() };
36
+ const base = { ...ownFields, hidden: z.boolean().optional(), searchPublic: z.boolean().optional(), page: z.string().optional() };
37
37
  return z.union([
38
38
  z.object({ ...base, pages: z.array(navItemSchema) }).strict(),
39
39
  z.object({ ...base, tabs: z.array(tabSchema).min(1) }).strict(),
@@ -65,6 +65,7 @@ const productSchema = z.lazy(
65
65
  () => withChildren({ product: z.string(), icon: z.string().optional(), description: z.string().optional() })
66
66
  );
67
67
  const MAX_TAB_LEVELS = 2;
68
+ const MAX_TAB_MENU_LEVELS = 2;
68
69
  const globalSchema = z.object({ dropdowns: z.array(dropdownSchema).min(1) });
69
70
  const navigationSchema = z.union([
70
71
  z.array(navItemSchema),
@@ -75,7 +76,7 @@ const navigationSchema = z.union([
75
76
  z.object({ global: globalSchema.optional(), products: z.array(productSchema).min(1) }).strict()
76
77
  ]).superRefine((navigation, ctx) => {
77
78
  const CONTAINERS = ["tabs", "versions", "languages", "dropdowns", "products"];
78
- const walk = (node, path, language, tabs) => {
79
+ const walk = (node, path, language, tabs, menu = 0) => {
79
80
  if (!node || typeof node !== "object" || Array.isArray(node)) return;
80
81
  const own = node;
81
82
  for (const key of CONTAINERS) {
@@ -97,8 +98,24 @@ const navigationSchema = z.union([
97
98
  });
98
99
  continue;
99
100
  }
101
+ const menuLevel = key !== "dropdowns" ? 0 : "tab" in own ? 1 : "dropdown" in own && menu > 0 ? menu + 1 : 0;
102
+ if (menuLevel > MAX_TAB_MENU_LEVELS) {
103
+ ctx.addIssue({
104
+ code: "custom",
105
+ path: [...path, key],
106
+ message: `A tab's menu goes ${MAX_TAB_MENU_LEVELS} levels deep at most - its dropdowns, and the dropdowns inside each of them - and these are a third level (inside "${String(own.dropdown)}"). Use products or groups for this level instead.`
107
+ });
108
+ continue;
109
+ }
100
110
  items.forEach((item, i) => {
101
111
  const own2 = item;
112
+ if (own2?.page !== void 0 && own2.href !== void 0) {
113
+ ctx.addIssue({
114
+ code: "custom",
115
+ path: [...path, key, i, "page"],
116
+ message: "An item with `href` is a link, so it has no page of its own - remove `page`, or `href`."
117
+ });
118
+ }
102
119
  if (own2?.searchPublic === true && own2.hidden !== true) {
103
120
  ctx.addIssue({
104
121
  code: "custom",
@@ -108,7 +125,7 @@ const navigationSchema = z.union([
108
125
  }
109
126
  const inner = key === "languages" ? String(item?.language ?? "") : language;
110
127
  const tab = item?.tab;
111
- walk(item, [...path, key, i], inner, key === "tabs" ? [...tabs, String(tab ?? "")] : tabs);
128
+ walk(item, [...path, key, i], inner, key === "tabs" ? [...tabs, String(tab ?? "")] : tabs, menuLevel);
112
129
  });
113
130
  }
114
131
  };
@@ -948,6 +965,7 @@ function validateDocsConfig(rawText) {
948
965
  export {
949
966
  CONTEXT_MENU_OPTIONS,
950
967
  MAX_TAB_LEVELS,
968
+ MAX_TAB_MENU_LEVELS,
951
969
  MCP_MENU_OPTIONS,
952
970
  ROOT_ALLOWED_EXTRA_KEYS,
953
971
  contextMenuOptions,
@@ -132,8 +132,12 @@ export type NavChildren =
132
132
  /** Any navigation item can be hidden: reachable only by its address - no
133
133
  * switcher, tab or menu lists it, and its pages search only among
134
134
  * themselves (plus the public ones, with `searchPublic`). See
135
- * lib/hidden-sections.js. */
136
- export type Hideable = { hidden?: boolean; searchPublic?: boolean };
135
+ * lib/hidden-sections.js.
136
+ * And any can have a `page` of its own: where choosing the item leads, in
137
+ * place of its first page - an overview of what's in it. In a sidebar too,
138
+ * it opens there; otherwise it opens inside the item (resolveLandings() in
139
+ * lib/config.ts). */
140
+ export type Hideable = { hidden?: boolean; searchPublic?: boolean; page?: string };
137
141
 
138
142
  export type TabItem = { tab: string; icon?: string } & Hideable & NavChildren;
139
143
  export type VersionItem = { version: string; label?: string; tag?: string; default?: boolean } & Hideable & NavChildren;
@@ -149,7 +153,7 @@ export type ProductItem = { product: string; icon?: string; description?: string
149
153
  // rule this schema exists to enforce (mirroring Mintlify's own "a tab
150
154
  // cannot contain both anchors and groups at the same level").
151
155
  function withChildren<Base extends z.ZodRawShape>(ownFields: Base) {
152
- const base = { ...ownFields, hidden: z.boolean().optional(), searchPublic: z.boolean().optional() };
156
+ const base = { ...ownFields, hidden: z.boolean().optional(), searchPublic: z.boolean().optional(), page: z.string().optional() };
153
157
  return z.union([
154
158
  z.object({ ...base, pages: z.array(navItemSchema) }).strict(),
155
159
  z.object({ ...base, tabs: z.array(tabSchema).min(1) }).strict(),
@@ -216,6 +220,9 @@ export type NavigationConfig =
216
220
 
217
221
  /** Levels of tabs a page can sit under - one row of the top bar each. */
218
222
  export const MAX_TAB_LEVELS = 2;
223
+ /** Levels of dropdowns in a tab's menu - the menu, and a flyout beside an
224
+ * entry for the dropdowns inside it (lib/selector-placement.js). */
225
+ export const MAX_TAB_MENU_LEVELS = 2;
219
226
 
220
227
  const globalSchema = z.object({ dropdowns: z.array(dropdownSchema).min(1) });
221
228
 
@@ -231,7 +238,9 @@ const navigationSchema = z.union([
231
238
  // inside it would make a page two languages at once. And tabs take a row
232
239
  // of the top bar per level: two levels at most (TopBar.astro).
233
240
  const CONTAINERS = ['tabs', 'versions', 'languages', 'dropdowns', 'products'] as const;
234
- const walk = (node: unknown, path: (string | number)[], language: string | null, tabs: string[]) => {
241
+ // `menu`: the dropdown levels in a tab's menu down to `node` - 0 outside
242
+ // one, 1 for a dropdown right inside a tab, 2 for a dropdown inside that.
243
+ const walk = (node: unknown, path: (string | number)[], language: string | null, tabs: string[], menu = 0) => {
235
244
  if (!node || typeof node !== 'object' || Array.isArray(node)) return;
236
245
  const own = node as Record<string, unknown>;
237
246
  for (const key of CONTAINERS) {
@@ -253,8 +262,27 @@ const navigationSchema = z.union([
253
262
  });
254
263
  continue;
255
264
  }
265
+ // Dropdowns right inside a tab are its menu; dropdowns inside one of
266
+ // those, a flyout beside its entry. Any other level of dropdowns starts
267
+ // its own count.
268
+ const menuLevel = key !== 'dropdowns' ? 0 : 'tab' in own ? 1 : 'dropdown' in own && menu > 0 ? menu + 1 : 0;
269
+ if (menuLevel > MAX_TAB_MENU_LEVELS) {
270
+ ctx.addIssue({
271
+ code: 'custom',
272
+ path: [...path, key],
273
+ message: `A tab's menu goes ${MAX_TAB_MENU_LEVELS} levels deep at most - its dropdowns, and the dropdowns inside each of them - and these are a third level (inside "${String(own.dropdown)}"). Use products or groups for this level instead.`,
274
+ });
275
+ continue;
276
+ }
256
277
  items.forEach((item, i) => {
257
- const own = item as { hidden?: unknown; searchPublic?: unknown };
278
+ const own = item as { hidden?: unknown; searchPublic?: unknown; page?: unknown; href?: unknown };
279
+ if (own?.page !== undefined && own.href !== undefined) {
280
+ ctx.addIssue({
281
+ code: 'custom',
282
+ path: [...path, key, i, 'page'],
283
+ message: 'An item with `href` is a link, so it has no page of its own - remove `page`, or `href`.',
284
+ });
285
+ }
258
286
  if (own?.searchPublic === true && own.hidden !== true) {
259
287
  ctx.addIssue({
260
288
  code: 'custom',
@@ -264,7 +292,7 @@ const navigationSchema = z.union([
264
292
  }
265
293
  const inner = key === 'languages' ? String((item as { language?: unknown })?.language ?? '') : language;
266
294
  const tab = (item as { tab?: unknown })?.tab;
267
- walk(item, [...path, key, i], inner, key === 'tabs' ? [...tabs, String(tab ?? '')] : tabs);
295
+ walk(item, [...path, key, i], inner, key === 'tabs' ? [...tabs, String(tab ?? '')] : tabs, menuLevel);
268
296
  });
269
297
  }
270
298
  };
package/src/lib/config.ts CHANGED
@@ -2,6 +2,7 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { EXCLUDED_TOP_LEVEL_DIRS, navPageId } from './pages.js';
4
4
  import { isHidden } from './hidden-sections.js';
5
+ import { itemPage, childLevel, resolveLandings as resolveLandingsJs } from './item-pages.js';
5
6
  import matter from 'gray-matter';
6
7
  import { writedocsTempDir } from './writedocs-temp-dir.js';
7
8
  import { readableTextOn } from './color.js';
@@ -758,6 +759,58 @@ export function resolveSections(navigation: NavigationConfig): Section[] {
758
759
  return sections;
759
760
  }
760
761
 
762
+ // --- An item's own page ------------------------------------------------
763
+ //
764
+ // A tab, version, language, dropdown or product can have a `page`: choosing
765
+ // the item opens it (firstSlugOf() above). How such a page is shown when no
766
+ // sidebar lists it - inside its item - is lib/item-pages.js; the route is
767
+ // landingRoutes in [...slug].astro.
768
+
769
+ export interface Landing {
770
+ /** The page's id. */
771
+ slug: string;
772
+ /** The levels down to the item, the item last. */
773
+ path: PathSegment[];
774
+ /** The item's own sidebar - empty when it holds tabs, products, ... */
775
+ pages: NavItem[];
776
+ item: NamedContainer;
777
+ }
778
+
779
+ export function resolveLandings(navigation: NavigationConfig): Landing[] {
780
+ return resolveLandingsJs(navigation) as Landing[];
781
+ }
782
+
783
+ /** The selectors for an item's own page shown inside the item: the levels
784
+ * down to the item, as for any page, plus the item's own options with none
785
+ * chosen - the switcher shows the item's name until the reader picks one
786
+ * (`placeholder`, currentOption() in lib/selector-placement.js). */
787
+ export function landingSelectors(landing: Landing, hrefForSlug: (slug: string) => string): Selector[] {
788
+ const selectors = buildSelectors(landing.path, hrefForSlug);
789
+ const level = childLevel(landing.item) as { kind: PathSegment['kind']; items: NamedContainer[] } | null;
790
+ if (!level) return selectors;
791
+ selectors.push({
792
+ kind: level.kind,
793
+ placeholder: {
794
+ label: labelOf(landing.item),
795
+ icon: iconOf(landing.item),
796
+ description: 'description' in landing.item ? landing.item.description : undefined,
797
+ },
798
+ options: level.items.flatMap((child) => {
799
+ if (isHidden(child)) return [];
800
+ return {
801
+ label: labelOf(child),
802
+ icon: iconOf(child),
803
+ tag: 'tag' in child ? child.tag : undefined,
804
+ description: 'description' in child ? child.description : undefined,
805
+ href: 'href' in child ? child.href : hrefForSlug(firstSlugOf(child as Container) ?? 'index'),
806
+ active: false,
807
+ dropdown: dropdownMenuOf(child as Container, hrefForSlug),
808
+ };
809
+ }),
810
+ });
811
+ return selectors;
812
+ }
813
+
761
814
  /** Which Section (by index into resolveSections()'s result) a page belongs to. */
762
815
  export function findSectionIndexForSlug(sections: Section[], slug: string): number {
763
816
  const index = sections.findIndex((s) => flattenNav(s.pages).some((entry) => entry.slug === slug));
@@ -797,6 +850,9 @@ function firstSlugAmong(items: Container[]): string | null {
797
850
  }
798
851
 
799
852
  export function firstSlugOf(node: Container): string | null {
853
+ // An item with a `page` of its own opens there (lib/item-pages.js).
854
+ const own = itemPage(node);
855
+ if (own !== null) return own;
800
856
  if ('pages' in node) return flattenNav(node.pages)[0]?.slug ?? null;
801
857
  if ('href' in node) return null;
802
858
  if ('tabs' in node) return firstSlugAmong(node.tabs);
@@ -937,11 +993,16 @@ export interface SelectorOption {
937
993
  // Set when this option's own container is a `dropdowns` list (e.g. a
938
994
  // tab whose content is `dropdowns` instead of `pages`) - the tab pill
939
995
  // itself becomes a dropdown-trigger showing these as its menu, rather
940
- // than a separate dropdown control rendered alongside it. Only ever
941
- // populated one level deep (a dropdown option doesn't itself get a
942
- // nested `dropdown` - matches the one level of "a tab/dropdown owns a
943
- // dropdowns list" this is meant to cover).
996
+ // than a separate dropdown control rendered alongside it.
944
997
  dropdown?: SelectorOption[];
998
+ // On an entry of that menu holding dropdowns of its own: those, shown in a
999
+ // flyout beside the entry (TopBar.astro). A tab's menu goes two levels deep
1000
+ // at most (MAX_TAB_MENU_LEVELS in config-schema.ts), so a flyout's entries
1001
+ // have none.
1002
+ submenu?: SelectorOption[];
1003
+ // On an entry with a `submenu`: the entry's own `page`, if it has one -
1004
+ // clicking the entry opens it. Without one, clicking opens the flyout.
1005
+ pageHref?: string;
945
1006
  }
946
1007
 
947
1008
  export interface Selector {
@@ -952,30 +1013,45 @@ export interface Selector {
952
1013
  // not dropped, so the levels after it are placed by their real parent
953
1014
  // (lib/selector-placement.js).
954
1015
  hidden?: boolean;
1016
+ // No option is chosen on this level - the page is an item's own page,
1017
+ // shown above its options (landingSelectors()). A switcher shows this
1018
+ // instead of a current option (currentOption() in lib/selector-placement.js).
1019
+ placeholder?: { label: string; icon?: string; description?: string };
955
1020
  }
956
1021
 
957
1022
  /** An option's own `dropdowns` menu, if it has one (see SelectorOption.dropdown
958
- * above) - `activeSegment` is the *next* PathSegment after this option's own
959
- * segment, only passed when this option is the active one on its level, so a
960
- * sibling option that also happens to own `dropdowns` doesn't spuriously mark
961
- * one of its entries active just because some *other* option is currently
962
- * selected. */
1023
+ * above), with a `submenu` on each entry that holds dropdowns of its own.
1024
+ * `activePath` is the path *below* this option's own segment, only passed
1025
+ * when this option is the active one on its level, so a sibling option that
1026
+ * also happens to own `dropdowns` doesn't spuriously mark one of its entries
1027
+ * active just because some *other* option is currently selected. */
963
1028
  function dropdownMenuOf(
964
1029
  node: NavChildren,
965
1030
  hrefForSlug: (slug: string) => string,
966
- activeSegment: PathSegment | undefined
1031
+ activePath: PathSegment[] = [],
1032
+ depth = 1
967
1033
  ): SelectorOption[] | undefined {
968
1034
  if (!('dropdowns' in node)) return undefined;
969
- return node.dropdowns
970
- .map((d, i) => ({
1035
+ const [segment, ...below] = activePath;
1036
+ return node.dropdowns.flatMap((d, i): SelectorOption[] => {
1037
+ if (isHidden(d)) return [];
1038
+ const active = segment?.kind === 'dropdown' && segment.index === i;
1039
+ const option: SelectorOption = {
971
1040
  label: d.dropdown,
972
1041
  icon: iconOf(d),
973
1042
  href: 'href' in d ? d.href : hrefForSlug(firstSlugOf(d) ?? 'index'),
974
- active: activeSegment?.kind === 'dropdown' && activeSegment.index === i,
975
- hidden: isHidden(d),
976
- }))
977
- .filter((d) => !d.hidden)
978
- .map(({ hidden: _hidden, ...option }) => option);
1043
+ active,
1044
+ };
1045
+ if (depth === 1 && 'dropdowns' in d) {
1046
+ const submenu = dropdownMenuOf(d, hrefForSlug, active ? below : [], depth + 1);
1047
+ if (submenu && submenu.length > 0) {
1048
+ option.submenu = submenu;
1049
+ const own = itemPage(d);
1050
+ if (own !== null) option.pageHref = hrefForSlug(own);
1051
+ }
1052
+ }
1053
+ return [option];
1054
+ });
979
1055
  }
980
1056
 
981
1057
  /** `activePagePosition` is the reader's current page's own index within
@@ -1014,7 +1090,7 @@ export function buildSelectors(
1014
1090
  description: 'description' in item ? item.description : undefined,
1015
1091
  href: 'href' in item ? item.href : hrefForSlug(targetSlug),
1016
1092
  active: isActive,
1017
- dropdown: dropdownMenuOf(item, hrefForSlug, isActive ? path[segIndex + 1] : undefined),
1093
+ dropdown: dropdownMenuOf(item, hrefForSlug, isActive ? path.slice(segIndex + 1) : []),
1018
1094
  };
1019
1095
  }),
1020
1096
  };