@writedocs/generator 0.10.20 → 0.11.0

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.
Files changed (52) hide show
  1. package/astro.config.mjs +32 -8
  2. package/package.json +1 -1
  3. package/src/cli/base-path-layout.js +44 -0
  4. package/src/cli/build.js +177 -168
  5. package/src/cli/check-built-styles.js +41 -33
  6. package/src/cli/dev.js +261 -244
  7. package/src/cli/run-pagefind.js +154 -148
  8. package/src/cli/write-mcp-files.js +103 -96
  9. package/src/cli/write-redirects-file.js +25 -8
  10. package/src/components/AppIcon.astro +51 -50
  11. package/src/components/Card.astro +193 -192
  12. package/src/components/CopyPageMenu.astro +374 -370
  13. package/src/components/Hint.astro +188 -187
  14. package/src/components/Icon.astro +72 -71
  15. package/src/components/Image.astro +3 -2
  16. package/src/components/Tile.astro +67 -66
  17. package/src/components/Video.astro +137 -136
  18. package/src/layout/BaseLayout.astro +21 -12
  19. package/src/layout/components/AnalyticsScripts.astro +6 -2
  20. package/src/layout/components/Breadcrumbs.astro +98 -97
  21. package/src/layout/components/ConsentBanner.astro +119 -118
  22. package/src/layout/components/MobileMenu.astro +229 -228
  23. package/src/layout/components/NavTree.astro +393 -392
  24. package/src/layout/components/Sidebar.astro +232 -231
  25. package/src/layout/components/SiteFooter.astro +87 -86
  26. package/src/layout/components/TopBar.astro +386 -385
  27. package/src/lib/agent-markdown.js +164 -162
  28. package/src/lib/asset-dimensions.js +89 -89
  29. package/src/lib/base-path.js +90 -0
  30. package/src/lib/config-schema.js +10 -0
  31. package/src/lib/config-schema.ts +17 -0
  32. package/src/lib/config.ts +1314 -1289
  33. package/src/lib/consent.js +108 -102
  34. package/src/lib/json-schema-descriptions.js +1 -0
  35. package/src/lib/link-check.js +7 -2
  36. package/src/lib/llms-index.ts +90 -88
  37. package/src/lib/mcp-dev-integration.js +65 -60
  38. package/src/lib/mcp-index.ts +102 -101
  39. package/src/lib/project-files-integration.js +2 -2
  40. package/src/lib/rehype-base-path.js +62 -0
  41. package/src/lib/robots-txt.js +21 -16
  42. package/src/lib/seo-tags.js +155 -140
  43. package/src/lib/site-base.ts +27 -0
  44. package/src/lib/styles-asset-integration.js +23 -10
  45. package/src/lib/wdignore-cases.json +195 -195
  46. package/src/lib/wdignore.js +177 -177
  47. package/src/pages/404.astro +63 -62
  48. package/src/pages/[...slug].astro +1604 -1597
  49. package/src/pages/[...slug].md.ts +93 -93
  50. package/src/pages/llms-full.txt.ts +88 -86
  51. package/src/scripts/search.ts +241 -237
  52. package/writedocs.schema.json +6 -0
@@ -1,385 +1,386 @@
1
- ---
2
- // The site's persistent header: brand, version/language/product switchers,
3
- // tabs + global dropdowns (second row), writedocs.json's `topbar.links` (as a
4
- // plain row above 860px, collapsed into a single ellipsis dropdown below
5
- // it), the search trigger, and the theme toggle. Also renders the
6
- // hamburger button that opens MobileMenu.astro's own drawer - the button
7
- // itself lives here (it's positioned as the first child of
8
- // .wd-topbar-inner, part of this row), the panel it opens is a separate
9
- // component/file.
10
- //
11
- // Split out of BaseLayout.astro, which had grown to ~2200 lines covering
12
- // several unrelated concerns in one file - see that component's own
13
- // comment for the fuller rationale.
14
- import { isExternalHref, type DocsConfig, type Selector, type GlobalDropdownView } from '../../lib/config';
15
- import AppIcon from '../../components/AppIcon.astro';
16
- import { logoWidth } from '../../lib/image-size.js';
17
- import { selectorPlacements, hasMobileMenu, currentOption } from '../../lib/selector-placement.js';
18
- import '../styles/dropdown.css';
19
- import '../styles/topbar.css';
20
-
21
- interface Props {
22
- config: DocsConfig;
23
- // One Selector per level of the active page's navigation path (tabs,
24
- // versions, languages, products, or a dropdown used as a nested level) -
25
- // see resolveSections()/buildSelectors() in lib/config.ts.
26
- selectors: Selector[];
27
- // The always-visible topbar dropdown list from navigation.global.dropdowns.
28
- globalDropdowns: GlobalDropdownView[];
29
- // Whether this page would show a sidebar at all (mode === 'default' or
30
- // 'wide') - gates whether the hamburger toggle renders, same condition
31
- // MobileMenu.astro itself is gated on for the panel it opens.
32
- showSidebarCol: boolean;
33
- logoLight?: string;
34
- logoDark?: string;
35
- brandLabel?: string;
36
- }
37
- const { config, selectors, globalDropdowns, showSidebarCol, logoLight, logoDark, brandLabel } = Astro.props as Props;
38
-
39
- // The topbar is two stacked rows, matching Mintlify's own layout: a top
40
- // row with the brand and the "pick one" switchers (versions/languages/
41
- // products, or a dropdown used as a nested path segment) on the right,
42
- // and a second row underneath for tabs plus the always-visible global
43
- // dropdowns - both of which behave like a row of labeled links rather
44
- // than a single current-value switcher. Tabs inside a tab get a third row.
45
- //
46
- // A dropdown container nested directly inside a tab (writedocs.json's "API
47
- // Reference" tab having a `dropdowns` array instead of `pages`) reads as
48
- // part of that tab's own local navigation, not as an independent
49
- // top-level "pick one" choice - it's rendered by turning the *tab's own
50
- // pill* into a dropdown-trigger (see SelectorOption.dropdown /
51
- // buildSelectors() in lib/config.ts, and the tabSelectors.map below),
52
- // rather than as a separate control. So unlike a root-level dropdown/
53
- // version/language/product selector (which does surface as a brand-row
54
- // switcher), this one is dropped from switcherSelectors entirely -
55
- // `selectors` is in root-to-leaf path order, so "nested directly inside a
56
- // tab" just means the previous entry in the array is the 'tab' selector.
57
- // Which level goes where - lib/selector-placement.js. A product inside a tab
58
- // or dropdown sits at the top of the sidebar instead (Sidebar.astro), when
59
- // the page has one.
60
- const placements = selectorPlacements(selectors, { sidebar: showSidebarCol });
61
- const showMenuButton = hasMobileMenu({ sidebar: showSidebarCol, selectors, globalDropdowns });
62
- const switcherSelectors = selectors.filter((_, i) => placements[i] === 'topbar');
63
- const tabSelectors = selectors.filter((_, i) => placements[i] === 'tabs');
64
- // One row per level of tabs: a tab holding its own tabs gets a second row
65
- // underneath, with that tab's tabs. The global dropdowns stay in the first
66
- // row, which renders on its own when there are only those.
67
- const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length > 0 ? [null] : [];
68
- ---
69
- <header class="wd-topbar">
70
- <div class="wd-topbar-row wd-topbar-row-brand">
71
- <div class="wd-topbar-inner">
72
- {/* Only rendered on pages that have a mobile menu - a sidebar, or
73
- navigation the top bar hides on a phone (hasMobileMenu(), the same
74
- condition MobileMenu.astro's own rendering is gated on). Hidden
75
- entirely above 860px via CSS (.wd-mobile-menu-toggle's own media
76
- query in topbar.css), not JS - so there's no flash-of-hamburger on
77
- a desktop-width load. */}
78
- {showMenuButton && (
79
- <button
80
- type="button"
81
- class="wd-mobile-menu-toggle"
82
- aria-label="Open menu"
83
- aria-expanded="false"
84
- aria-controls="wd-mobile-menu"
85
- data-mobile-menu-trigger
86
- >
87
- <svg class="wd-mobile-menu-icon wd-mobile-menu-icon-bars" width="18" height="18" viewBox="0 0 18 18" aria-hidden="true">
88
- <path d="M2.5 5H15.5M2.5 9H15.5M2.5 13H15.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
89
- </svg>
90
- <svg class="wd-mobile-menu-icon wd-mobile-menu-icon-close" width="18" height="18" viewBox="0 0 18 18" aria-hidden="true">
91
- <path d="M4 4L14 14M14 4L4 14" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
92
- </svg>
93
- </button>
94
- )}
95
- <a class="wd-topbar-brand" href="/">
96
- {logoLight && <img src={logoLight} alt={config.name} height="24" width={logoWidth(logoLight)} class="wd-logo-light" />}
97
- {logoDark && <img src={logoDark} alt={config.name} height="24" width={logoWidth(logoDark)} class="wd-logo-dark" />}
98
- {brandLabel && <span title={brandLabel}>{brandLabel}</span>}
99
- </a>
100
-
101
- {switcherSelectors.length > 0 && (
102
- <nav class="wd-topbar-switchers" aria-label="Version, language and product selection">
103
- {switcherSelectors.map((sel) => {
104
- // versions / languages / products, and a dropdown used as a
105
- // nested path segment, all render as a single switcher: the
106
- // trigger shows the *current* option, the menu lists the
107
- // alternatives - unlike tabs, where every option is its own
108
- // always-visible pill in the row below.
109
- const current = currentOption(sel);
110
- return (
111
- <div class="wd-dropdown" data-selector-kind={sel.kind}>
112
- <button type="button" class="wd-dropdown-trigger wd-switcher-trigger" aria-expanded="false">
113
- <AppIcon icon={current.icon} class="wd-tab-icon" />
114
- {current.label}
115
- {current.tag && <span class="wd-selector-tag">{current.tag}</span>}
116
- <svg class="wd-dropdown-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
117
- <path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
118
- </svg>
119
- </button>
120
- <div class="wd-dropdown-menu">
121
- <div class="wd-dropdown-menu-panel">
122
- {sel.options.map((opt) => (
123
- <a
124
- href={opt.href}
125
- class={opt.active ? 'active' : ''} aria-current={opt.active ? 'true' : undefined}
126
- target={isExternalHref(opt.href) ? '_blank' : undefined}
127
- rel={isExternalHref(opt.href) ? 'noopener noreferrer' : undefined}
128
- >
129
- <AppIcon icon={opt.icon} class="wd-tab-icon" />
130
- {opt.label}
131
- {opt.tag && <span class="wd-selector-tag">{opt.tag}</span>}
132
- </a>
133
- ))}
134
- </div>
135
- </div>
136
- </div>
137
- );
138
- })}
139
- </nav>
140
- )}
141
-
142
- <nav class="wd-topbar-links">
143
- {config.topbar.links.map((link) => (
144
- <a
145
- href={link.href}
146
- target={isExternalHref(link.href) ? '_blank' : undefined}
147
- rel={isExternalHref(link.href) ? 'noopener noreferrer' : undefined}
148
- aria-label={!link.label ? link.icon : undefined}
149
- >
150
- <AppIcon icon={link.icon} class="wd-tab-icon" />
151
- {link.label}
152
- </a>
153
- ))}
154
- </nav>
155
-
156
- {/* Below 860px, .wd-topbar-links above is hidden (see topbar.css)
157
- and this takes its place instead - same link set, same
158
- writedocs.json config.topbar.links, just collapsed behind a single
159
- icon button rather than an inline row of text links that would
160
- otherwise wrap and eat vertical space next to the brand. Reuses
161
- the existing .wd-dropdown/.wd-dropdown-trigger/.wd-dropdown-menu/
162
- .wd-dropdown-menu-panel pattern (see the switcher/tab dropdowns
163
- above) rather than inventing a new toggle mechanism -
164
- initDropdowns() (src/scripts/dropdowns.ts, wired below) already
165
- wires up every .wd-dropdown on the page generically, so this
166
- needs no JS of its own. */}
167
- {config.topbar.links.length > 0 && (
168
- <div class="wd-dropdown wd-topbar-links-mobile" data-selector-kind="topbar-links">
169
- <button
170
- type="button"
171
- class="wd-dropdown-trigger wd-topbar-links-toggle"
172
- aria-expanded="false"
173
- aria-label="More links"
174
- >
175
- <svg width="4" height="16" viewBox="0 0 4 16" aria-hidden="true">
176
- <circle cx="2" cy="2" r="1.7" fill="currentColor" />
177
- <circle cx="2" cy="8" r="1.7" fill="currentColor" />
178
- <circle cx="2" cy="14" r="1.7" fill="currentColor" />
179
- </svg>
180
- </button>
181
- <div class="wd-dropdown-menu">
182
- <div class="wd-dropdown-menu-panel">
183
- {config.topbar.links.map((link) => (
184
- <a
185
- href={link.href}
186
- target={isExternalHref(link.href) ? '_blank' : undefined}
187
- rel={isExternalHref(link.href) ? 'noopener noreferrer' : undefined}
188
- aria-label={!link.label ? link.icon : undefined}
189
- >
190
- <AppIcon icon={link.icon} class="wd-tab-icon" />
191
- {link.label}
192
- </a>
193
- ))}
194
- </div>
195
- </div>
196
- </div>
197
- )}
198
-
199
- <button type="button" class="wd-search-trigger" aria-label="Search" data-search-trigger>
200
- <svg class="wd-search-icon" width="14" height="14" viewBox="0 0 14 14" aria-hidden="true">
201
- <circle cx="6" cy="6" r="4.5" stroke="currentColor" stroke-width="1.4" fill="none" />
202
- <path d="M9.5 9.5L13 13" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" />
203
- </svg>
204
- <span class="wd-search-placeholder">Search...</span>
205
- <kbd class="wd-search-kbd">⌘K</kbd>
206
- </button>
207
-
208
- <button type="button" class="wd-theme-toggle" aria-label="Toggle color theme">
209
- <AppIcon icon="sun" class="wd-theme-icon wd-theme-icon-sun" />
210
- <AppIcon icon="moon" class="wd-theme-icon wd-theme-icon-moon" />
211
- </button>
212
- </div>
213
- </div>
214
-
215
- {tabRows.map((sel, row) => (
216
- <div class={`wd-topbar-row wd-topbar-row-tabs${row > 0 ? ' wd-topbar-row-subtabs' : ''}`}>
217
- <div class="wd-topbar-inner">
218
- {/* More tabs than fit: the row slides sideways instead of wrapping,
219
- with an arrow on each side that has more (src/scripts/tabs-strip.ts).
220
- The arrows are only for the mouse - keyboard focus slides a tab
221
- into view by itself. */}
222
- <div class="wd-tabs-strip" data-tabs-strip>
223
- <button type="button" class="wd-tabs-arrow wd-tabs-arrow-prev" tabindex="-1" aria-hidden="true" data-tabs-prev>
224
- <svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true">
225
- <path d="M8.5 3L4.5 7L8.5 11" stroke="currentColor" stroke-width="1.6" fill="none" stroke-linecap="round" stroke-linejoin="round" />
226
- </svg>
227
- </button>
228
- <div class="wd-tabs-viewport">
229
- <nav class="wd-topbar-tabs" aria-label={row === 0 ? 'Sections' : 'Subsections'}>
230
- {(sel?.options ?? []).map((opt) =>
231
- opt.dropdown ? (
232
- // A tab whose own content is `dropdowns` (not `pages`)
233
- // renders as a dropdown-trigger in place of the plain
234
- // pill - the tab's own label/icon stay on the trigger
235
- // (not "whichever dropdown is current", so it reads as
236
- // "this tab, which happens to expand" rather than
237
- // jumping around as you navigate its sub-pages), and its
238
- // dropdowns become the menu.
239
- <div class="wd-dropdown" data-selector-kind="tab">
240
- <button
241
- type="button"
242
- class={`wd-dropdown-trigger wd-tab-link ${opt.active ? 'active' : ''}`}
243
- aria-expanded="false"
244
- >
245
- <AppIcon icon={opt.icon} class="wd-tab-icon" />
246
- {opt.label}
247
- <svg class="wd-dropdown-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
248
- <path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
249
- </svg>
250
- </button>
251
- <div class="wd-dropdown-menu">
252
- <div class="wd-dropdown-menu-panel">
253
- {opt.dropdown.map((d) =>
254
- d.submenu ? (
255
- // An entry holding dropdowns of its own: they open in
256
- // a flyout beside it, on hover, or on a click on the
257
- // arrow - or on the entry itself when it has no page
258
- // of its own to open (src/scripts/dropdowns.ts).
259
- <div class={`wd-submenu ${d.active ? 'wd-submenu-active' : ''}`}>
260
- <div class="wd-submenu-row">
261
- {d.pageHref ? (
262
- <a href={d.pageHref} class={`wd-submenu-entry ${d.active ? 'active' : ''}`} aria-current={d.active ? 'true' : undefined}>
263
- <AppIcon icon={d.icon} class="wd-tab-icon" />
264
- <span class="wd-submenu-label">{d.label}</span>
265
- </a>
266
- ) : null}
267
- <button
268
- type="button"
269
- class={`wd-submenu-toggle ${d.pageHref ? 'wd-submenu-arrow' : `wd-submenu-entry ${d.active ? 'active' : ''}`}`}
270
- aria-expanded="false"
271
- aria-label={d.pageHref ? `${d.label} - more` : undefined}
272
- >
273
- {!d.pageHref && <AppIcon icon={d.icon} class="wd-tab-icon" />}
274
- {!d.pageHref && <span class="wd-submenu-label">{d.label}</span>}
275
- <svg class="wd-submenu-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
276
- <path d="M3.5 2L6.5 5L3.5 8" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
277
- </svg>
278
- </button>
279
- </div>
280
- <div class="wd-submenu-panel">
281
- <div class="wd-dropdown-menu-panel">
282
- {d.pageHref ? (
283
- <a href={d.pageHref} class="wd-submenu-heading">{d.label}</a>
284
- ) : (
285
- <span class="wd-submenu-heading">{d.label}</span>
286
- )}
287
- {d.submenu.map((sub) => (
288
- <a
289
- href={sub.href}
290
- class={sub.active ? 'active' : ''} aria-current={sub.active ? 'true' : undefined}
291
- target={isExternalHref(sub.href) ? '_blank' : undefined}
292
- rel={isExternalHref(sub.href) ? 'noopener noreferrer' : undefined}
293
- >
294
- <AppIcon icon={sub.icon} class="wd-tab-icon" />
295
- {sub.label}
296
- </a>
297
- ))}
298
- </div>
299
- </div>
300
- </div>
301
- ) : (
302
- <a
303
- href={d.href}
304
- class={d.active ? 'active' : ''} aria-current={d.active ? 'true' : undefined}
305
- target={isExternalHref(d.href) ? '_blank' : undefined}
306
- rel={isExternalHref(d.href) ? 'noopener noreferrer' : undefined}
307
- >
308
- <AppIcon icon={d.icon} class="wd-tab-icon" />
309
- {d.label}
310
- </a>
311
- )
312
- )}
313
- </div>
314
- </div>
315
- </div>
316
- ) : (
317
- <a
318
- href={opt.href}
319
- class={`wd-tab-link ${opt.active ? 'active' : ''}`}
320
- aria-current={opt.active ? 'true' : undefined}
321
- target={isExternalHref(opt.href) ? '_blank' : undefined}
322
- rel={isExternalHref(opt.href) ? 'noopener noreferrer' : undefined}
323
- >
324
- <AppIcon icon={opt.icon} class="wd-tab-icon" />
325
- {opt.label}
326
- </a>
327
- )
328
- )}
329
- {row === 0 &&
330
- globalDropdowns.map((d) =>
331
- d.href !== null ? (
332
- <a
333
- href={d.href}
334
- class="wd-tab-link"
335
- target={isExternalHref(d.href) ? '_blank' : undefined}
336
- rel={isExternalHref(d.href) ? 'noopener noreferrer' : undefined}
337
- >
338
- <AppIcon icon={d.icon} class="wd-tab-icon" />
339
- {d.label}
340
- </a>
341
- ) : (
342
- <div class="wd-dropdown">
343
- <button type="button" class="wd-dropdown-trigger" aria-expanded="false">
344
- <AppIcon icon={d.icon} class="wd-tab-icon" />
345
- {d.label}
346
- <svg class="wd-dropdown-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
347
- <path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
348
- </svg>
349
- </button>
350
- <div class="wd-dropdown-menu">
351
- <div class="wd-dropdown-menu-panel">
352
- {d.items.map((item) => (
353
- <a href={item.href} class={item.active ? 'active' : ''} aria-current={item.active ? 'true' : undefined}>{item.label}</a>
354
- ))}
355
- </div>
356
- </div>
357
- </div>
358
- )
359
- )}
360
- </nav>
361
- </div>
362
- <button type="button" class="wd-tabs-arrow wd-tabs-arrow-next" tabindex="-1" aria-hidden="true" data-tabs-next>
363
- <svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true">
364
- <path d="M5.5 3L9.5 7L5.5 11" stroke="currentColor" stroke-width="1.6" fill="none" stroke-linecap="round" stroke-linejoin="round" />
365
- </svg>
366
- </button>
367
- </div>
368
- </div>
369
- </div>
370
- ))}
371
- </header>
372
- <script>
373
- import { initDropdowns } from '../../scripts/dropdowns';
374
- import { initThemeToggle } from '../../scripts/theme-toggle';
375
- import { initTabsStrips } from '../../scripts/tabs-strip';
376
-
377
- initDropdowns(document);
378
- initThemeToggle(document);
379
- initTabsStrips(document);
380
- document.addEventListener('astro:page-load', () => {
381
- initDropdowns(document);
382
- initThemeToggle(document);
383
- initTabsStrips(document);
384
- });
385
- </script>
1
+ ---
2
+ // The site's persistent header: brand, version/language/product switchers,
3
+ // tabs + global dropdowns (second row), writedocs.json's `topbar.links` (as a
4
+ // plain row above 860px, collapsed into a single ellipsis dropdown below
5
+ // it), the search trigger, and the theme toggle. Also renders the
6
+ // hamburger button that opens MobileMenu.astro's own drawer - the button
7
+ // itself lives here (it's positioned as the first child of
8
+ // .wd-topbar-inner, part of this row), the panel it opens is a separate
9
+ // component/file.
10
+ //
11
+ // Split out of BaseLayout.astro, which had grown to ~2200 lines covering
12
+ // several unrelated concerns in one file - see that component's own
13
+ // comment for the fuller rationale.
14
+ import { isExternalHref, type DocsConfig, type Selector, type GlobalDropdownView } from '../../lib/config';
15
+ import AppIcon from '../../components/AppIcon.astro';
16
+ import { logoWidth } from '../../lib/image-size.js';
17
+ import { selectorPlacements, hasMobileMenu, currentOption } from '../../lib/selector-placement.js';
18
+ import '../styles/dropdown.css';
19
+ import '../styles/topbar.css';
20
+ import { siteHref } from '../../lib/site-base';
21
+
22
+ interface Props {
23
+ config: DocsConfig;
24
+ // One Selector per level of the active page's navigation path (tabs,
25
+ // versions, languages, products, or a dropdown used as a nested level) -
26
+ // see resolveSections()/buildSelectors() in lib/config.ts.
27
+ selectors: Selector[];
28
+ // The always-visible topbar dropdown list from navigation.global.dropdowns.
29
+ globalDropdowns: GlobalDropdownView[];
30
+ // Whether this page would show a sidebar at all (mode === 'default' or
31
+ // 'wide') - gates whether the hamburger toggle renders, same condition
32
+ // MobileMenu.astro itself is gated on for the panel it opens.
33
+ showSidebarCol: boolean;
34
+ logoLight?: string;
35
+ logoDark?: string;
36
+ brandLabel?: string;
37
+ }
38
+ const { config, selectors, globalDropdowns, showSidebarCol, logoLight, logoDark, brandLabel } = Astro.props as Props;
39
+
40
+ // The topbar is two stacked rows, matching Mintlify's own layout: a top
41
+ // row with the brand and the "pick one" switchers (versions/languages/
42
+ // products, or a dropdown used as a nested path segment) on the right,
43
+ // and a second row underneath for tabs plus the always-visible global
44
+ // dropdowns - both of which behave like a row of labeled links rather
45
+ // than a single current-value switcher. Tabs inside a tab get a third row.
46
+ //
47
+ // A dropdown container nested directly inside a tab (writedocs.json's "API
48
+ // Reference" tab having a `dropdowns` array instead of `pages`) reads as
49
+ // part of that tab's own local navigation, not as an independent
50
+ // top-level "pick one" choice - it's rendered by turning the *tab's own
51
+ // pill* into a dropdown-trigger (see SelectorOption.dropdown /
52
+ // buildSelectors() in lib/config.ts, and the tabSelectors.map below),
53
+ // rather than as a separate control. So unlike a root-level dropdown/
54
+ // version/language/product selector (which does surface as a brand-row
55
+ // switcher), this one is dropped from switcherSelectors entirely -
56
+ // `selectors` is in root-to-leaf path order, so "nested directly inside a
57
+ // tab" just means the previous entry in the array is the 'tab' selector.
58
+ // Which level goes where - lib/selector-placement.js. A product inside a tab
59
+ // or dropdown sits at the top of the sidebar instead (Sidebar.astro), when
60
+ // the page has one.
61
+ const placements = selectorPlacements(selectors, { sidebar: showSidebarCol });
62
+ const showMenuButton = hasMobileMenu({ sidebar: showSidebarCol, selectors, globalDropdowns });
63
+ const switcherSelectors = selectors.filter((_, i) => placements[i] === 'topbar');
64
+ const tabSelectors = selectors.filter((_, i) => placements[i] === 'tabs');
65
+ // One row per level of tabs: a tab holding its own tabs gets a second row
66
+ // underneath, with that tab's tabs. The global dropdowns stay in the first
67
+ // row, which renders on its own when there are only those.
68
+ const tabRows = tabSelectors.length > 0 ? tabSelectors : globalDropdowns.length > 0 ? [null] : [];
69
+ ---
70
+ <header class="wd-topbar">
71
+ <div class="wd-topbar-row wd-topbar-row-brand">
72
+ <div class="wd-topbar-inner">
73
+ {/* Only rendered on pages that have a mobile menu - a sidebar, or
74
+ navigation the top bar hides on a phone (hasMobileMenu(), the same
75
+ condition MobileMenu.astro's own rendering is gated on). Hidden
76
+ entirely above 860px via CSS (.wd-mobile-menu-toggle's own media
77
+ query in topbar.css), not JS - so there's no flash-of-hamburger on
78
+ a desktop-width load. */}
79
+ {showMenuButton && (
80
+ <button
81
+ type="button"
82
+ class="wd-mobile-menu-toggle"
83
+ aria-label="Open menu"
84
+ aria-expanded="false"
85
+ aria-controls="wd-mobile-menu"
86
+ data-mobile-menu-trigger
87
+ >
88
+ <svg class="wd-mobile-menu-icon wd-mobile-menu-icon-bars" width="18" height="18" viewBox="0 0 18 18" aria-hidden="true">
89
+ <path d="M2.5 5H15.5M2.5 9H15.5M2.5 13H15.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
90
+ </svg>
91
+ <svg class="wd-mobile-menu-icon wd-mobile-menu-icon-close" width="18" height="18" viewBox="0 0 18 18" aria-hidden="true">
92
+ <path d="M4 4L14 14M14 4L4 14" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" />
93
+ </svg>
94
+ </button>
95
+ )}
96
+ <a class="wd-topbar-brand" href={siteHref("/")}>
97
+ {logoLight && <img src={siteHref(logoLight)} alt={config.name} height="24" width={logoWidth(logoLight)} class="wd-logo-light" />}
98
+ {logoDark && <img src={siteHref(logoDark)} alt={config.name} height="24" width={logoWidth(logoDark)} class="wd-logo-dark" />}
99
+ {brandLabel && <span title={brandLabel}>{brandLabel}</span>}
100
+ </a>
101
+
102
+ {switcherSelectors.length > 0 && (
103
+ <nav class="wd-topbar-switchers" aria-label="Version, language and product selection">
104
+ {switcherSelectors.map((sel) => {
105
+ // versions / languages / products, and a dropdown used as a
106
+ // nested path segment, all render as a single switcher: the
107
+ // trigger shows the *current* option, the menu lists the
108
+ // alternatives - unlike tabs, where every option is its own
109
+ // always-visible pill in the row below.
110
+ const current = currentOption(sel);
111
+ return (
112
+ <div class="wd-dropdown" data-selector-kind={sel.kind}>
113
+ <button type="button" class="wd-dropdown-trigger wd-switcher-trigger" aria-expanded="false">
114
+ <AppIcon icon={current.icon} class="wd-tab-icon" />
115
+ {current.label}
116
+ {current.tag && <span class="wd-selector-tag">{current.tag}</span>}
117
+ <svg class="wd-dropdown-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
118
+ <path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
119
+ </svg>
120
+ </button>
121
+ <div class="wd-dropdown-menu">
122
+ <div class="wd-dropdown-menu-panel">
123
+ {sel.options.map((opt) => (
124
+ <a
125
+ href={siteHref(opt.href)}
126
+ class={opt.active ? 'active' : ''} aria-current={opt.active ? 'true' : undefined}
127
+ target={isExternalHref(opt.href) ? '_blank' : undefined}
128
+ rel={isExternalHref(opt.href) ? 'noopener noreferrer' : undefined}
129
+ >
130
+ <AppIcon icon={opt.icon} class="wd-tab-icon" />
131
+ {opt.label}
132
+ {opt.tag && <span class="wd-selector-tag">{opt.tag}</span>}
133
+ </a>
134
+ ))}
135
+ </div>
136
+ </div>
137
+ </div>
138
+ );
139
+ })}
140
+ </nav>
141
+ )}
142
+
143
+ <nav class="wd-topbar-links">
144
+ {config.topbar.links.map((link) => (
145
+ <a
146
+ href={siteHref(link.href)}
147
+ target={isExternalHref(link.href) ? '_blank' : undefined}
148
+ rel={isExternalHref(link.href) ? 'noopener noreferrer' : undefined}
149
+ aria-label={!link.label ? link.icon : undefined}
150
+ >
151
+ <AppIcon icon={link.icon} class="wd-tab-icon" />
152
+ {link.label}
153
+ </a>
154
+ ))}
155
+ </nav>
156
+
157
+ {/* Below 860px, .wd-topbar-links above is hidden (see topbar.css)
158
+ and this takes its place instead - same link set, same
159
+ writedocs.json config.topbar.links, just collapsed behind a single
160
+ icon button rather than an inline row of text links that would
161
+ otherwise wrap and eat vertical space next to the brand. Reuses
162
+ the existing .wd-dropdown/.wd-dropdown-trigger/.wd-dropdown-menu/
163
+ .wd-dropdown-menu-panel pattern (see the switcher/tab dropdowns
164
+ above) rather than inventing a new toggle mechanism -
165
+ initDropdowns() (src/scripts/dropdowns.ts, wired below) already
166
+ wires up every .wd-dropdown on the page generically, so this
167
+ needs no JS of its own. */}
168
+ {config.topbar.links.length > 0 && (
169
+ <div class="wd-dropdown wd-topbar-links-mobile" data-selector-kind="topbar-links">
170
+ <button
171
+ type="button"
172
+ class="wd-dropdown-trigger wd-topbar-links-toggle"
173
+ aria-expanded="false"
174
+ aria-label="More links"
175
+ >
176
+ <svg width="4" height="16" viewBox="0 0 4 16" aria-hidden="true">
177
+ <circle cx="2" cy="2" r="1.7" fill="currentColor" />
178
+ <circle cx="2" cy="8" r="1.7" fill="currentColor" />
179
+ <circle cx="2" cy="14" r="1.7" fill="currentColor" />
180
+ </svg>
181
+ </button>
182
+ <div class="wd-dropdown-menu">
183
+ <div class="wd-dropdown-menu-panel">
184
+ {config.topbar.links.map((link) => (
185
+ <a
186
+ href={siteHref(link.href)}
187
+ target={isExternalHref(link.href) ? '_blank' : undefined}
188
+ rel={isExternalHref(link.href) ? 'noopener noreferrer' : undefined}
189
+ aria-label={!link.label ? link.icon : undefined}
190
+ >
191
+ <AppIcon icon={link.icon} class="wd-tab-icon" />
192
+ {link.label}
193
+ </a>
194
+ ))}
195
+ </div>
196
+ </div>
197
+ </div>
198
+ )}
199
+
200
+ <button type="button" class="wd-search-trigger" aria-label="Search" data-search-trigger>
201
+ <svg class="wd-search-icon" width="14" height="14" viewBox="0 0 14 14" aria-hidden="true">
202
+ <circle cx="6" cy="6" r="4.5" stroke="currentColor" stroke-width="1.4" fill="none" />
203
+ <path d="M9.5 9.5L13 13" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" />
204
+ </svg>
205
+ <span class="wd-search-placeholder">Search...</span>
206
+ <kbd class="wd-search-kbd">⌘K</kbd>
207
+ </button>
208
+
209
+ <button type="button" class="wd-theme-toggle" aria-label="Toggle color theme">
210
+ <AppIcon icon="sun" class="wd-theme-icon wd-theme-icon-sun" />
211
+ <AppIcon icon="moon" class="wd-theme-icon wd-theme-icon-moon" />
212
+ </button>
213
+ </div>
214
+ </div>
215
+
216
+ {tabRows.map((sel, row) => (
217
+ <div class={`wd-topbar-row wd-topbar-row-tabs${row > 0 ? ' wd-topbar-row-subtabs' : ''}`}>
218
+ <div class="wd-topbar-inner">
219
+ {/* More tabs than fit: the row slides sideways instead of wrapping,
220
+ with an arrow on each side that has more (src/scripts/tabs-strip.ts).
221
+ The arrows are only for the mouse - keyboard focus slides a tab
222
+ into view by itself. */}
223
+ <div class="wd-tabs-strip" data-tabs-strip>
224
+ <button type="button" class="wd-tabs-arrow wd-tabs-arrow-prev" tabindex="-1" aria-hidden="true" data-tabs-prev>
225
+ <svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true">
226
+ <path d="M8.5 3L4.5 7L8.5 11" stroke="currentColor" stroke-width="1.6" fill="none" stroke-linecap="round" stroke-linejoin="round" />
227
+ </svg>
228
+ </button>
229
+ <div class="wd-tabs-viewport">
230
+ <nav class="wd-topbar-tabs" aria-label={row === 0 ? 'Sections' : 'Subsections'}>
231
+ {(sel?.options ?? []).map((opt) =>
232
+ opt.dropdown ? (
233
+ // A tab whose own content is `dropdowns` (not `pages`)
234
+ // renders as a dropdown-trigger in place of the plain
235
+ // pill - the tab's own label/icon stay on the trigger
236
+ // (not "whichever dropdown is current", so it reads as
237
+ // "this tab, which happens to expand" rather than
238
+ // jumping around as you navigate its sub-pages), and its
239
+ // dropdowns become the menu.
240
+ <div class="wd-dropdown" data-selector-kind="tab">
241
+ <button
242
+ type="button"
243
+ class={`wd-dropdown-trigger wd-tab-link ${opt.active ? 'active' : ''}`}
244
+ aria-expanded="false"
245
+ >
246
+ <AppIcon icon={opt.icon} class="wd-tab-icon" />
247
+ {opt.label}
248
+ <svg class="wd-dropdown-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
249
+ <path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
250
+ </svg>
251
+ </button>
252
+ <div class="wd-dropdown-menu">
253
+ <div class="wd-dropdown-menu-panel">
254
+ {opt.dropdown.map((d) =>
255
+ d.submenu ? (
256
+ // An entry holding dropdowns of its own: they open in
257
+ // a flyout beside it, on hover, or on a click on the
258
+ // arrow - or on the entry itself when it has no page
259
+ // of its own to open (src/scripts/dropdowns.ts).
260
+ <div class={`wd-submenu ${d.active ? 'wd-submenu-active' : ''}`}>
261
+ <div class="wd-submenu-row">
262
+ {d.pageHref ? (
263
+ <a href={siteHref(d.pageHref)} class={`wd-submenu-entry ${d.active ? 'active' : ''}`} aria-current={d.active ? 'true' : undefined}>
264
+ <AppIcon icon={d.icon} class="wd-tab-icon" />
265
+ <span class="wd-submenu-label">{d.label}</span>
266
+ </a>
267
+ ) : null}
268
+ <button
269
+ type="button"
270
+ class={`wd-submenu-toggle ${d.pageHref ? 'wd-submenu-arrow' : `wd-submenu-entry ${d.active ? 'active' : ''}`}`}
271
+ aria-expanded="false"
272
+ aria-label={d.pageHref ? `${d.label} - more` : undefined}
273
+ >
274
+ {!d.pageHref && <AppIcon icon={d.icon} class="wd-tab-icon" />}
275
+ {!d.pageHref && <span class="wd-submenu-label">{d.label}</span>}
276
+ <svg class="wd-submenu-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
277
+ <path d="M3.5 2L6.5 5L3.5 8" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
278
+ </svg>
279
+ </button>
280
+ </div>
281
+ <div class="wd-submenu-panel">
282
+ <div class="wd-dropdown-menu-panel">
283
+ {d.pageHref ? (
284
+ <a href={siteHref(d.pageHref)} class="wd-submenu-heading">{d.label}</a>
285
+ ) : (
286
+ <span class="wd-submenu-heading">{d.label}</span>
287
+ )}
288
+ {d.submenu.map((sub) => (
289
+ <a
290
+ href={siteHref(sub.href)}
291
+ class={sub.active ? 'active' : ''} aria-current={sub.active ? 'true' : undefined}
292
+ target={isExternalHref(sub.href) ? '_blank' : undefined}
293
+ rel={isExternalHref(sub.href) ? 'noopener noreferrer' : undefined}
294
+ >
295
+ <AppIcon icon={sub.icon} class="wd-tab-icon" />
296
+ {sub.label}
297
+ </a>
298
+ ))}
299
+ </div>
300
+ </div>
301
+ </div>
302
+ ) : (
303
+ <a
304
+ href={siteHref(d.href)}
305
+ class={d.active ? 'active' : ''} aria-current={d.active ? 'true' : undefined}
306
+ target={isExternalHref(d.href) ? '_blank' : undefined}
307
+ rel={isExternalHref(d.href) ? 'noopener noreferrer' : undefined}
308
+ >
309
+ <AppIcon icon={d.icon} class="wd-tab-icon" />
310
+ {d.label}
311
+ </a>
312
+ )
313
+ )}
314
+ </div>
315
+ </div>
316
+ </div>
317
+ ) : (
318
+ <a
319
+ href={siteHref(opt.href)}
320
+ class={`wd-tab-link ${opt.active ? 'active' : ''}`}
321
+ aria-current={opt.active ? 'true' : undefined}
322
+ target={isExternalHref(opt.href) ? '_blank' : undefined}
323
+ rel={isExternalHref(opt.href) ? 'noopener noreferrer' : undefined}
324
+ >
325
+ <AppIcon icon={opt.icon} class="wd-tab-icon" />
326
+ {opt.label}
327
+ </a>
328
+ )
329
+ )}
330
+ {row === 0 &&
331
+ globalDropdowns.map((d) =>
332
+ d.href !== null ? (
333
+ <a
334
+ href={siteHref(d.href)}
335
+ class="wd-tab-link"
336
+ target={isExternalHref(d.href) ? '_blank' : undefined}
337
+ rel={isExternalHref(d.href) ? 'noopener noreferrer' : undefined}
338
+ >
339
+ <AppIcon icon={d.icon} class="wd-tab-icon" />
340
+ {d.label}
341
+ </a>
342
+ ) : (
343
+ <div class="wd-dropdown">
344
+ <button type="button" class="wd-dropdown-trigger" aria-expanded="false">
345
+ <AppIcon icon={d.icon} class="wd-tab-icon" />
346
+ {d.label}
347
+ <svg class="wd-dropdown-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
348
+ <path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
349
+ </svg>
350
+ </button>
351
+ <div class="wd-dropdown-menu">
352
+ <div class="wd-dropdown-menu-panel">
353
+ {d.items.map((item) => (
354
+ <a href={siteHref(item.href)} class={item.active ? 'active' : ''} aria-current={item.active ? 'true' : undefined}>{item.label}</a>
355
+ ))}
356
+ </div>
357
+ </div>
358
+ </div>
359
+ )
360
+ )}
361
+ </nav>
362
+ </div>
363
+ <button type="button" class="wd-tabs-arrow wd-tabs-arrow-next" tabindex="-1" aria-hidden="true" data-tabs-next>
364
+ <svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true">
365
+ <path d="M5.5 3L9.5 7L5.5 11" stroke="currentColor" stroke-width="1.6" fill="none" stroke-linecap="round" stroke-linejoin="round" />
366
+ </svg>
367
+ </button>
368
+ </div>
369
+ </div>
370
+ </div>
371
+ ))}
372
+ </header>
373
+ <script>
374
+ import { initDropdowns } from '../../scripts/dropdowns';
375
+ import { initThemeToggle } from '../../scripts/theme-toggle';
376
+ import { initTabsStrips } from '../../scripts/tabs-strip';
377
+
378
+ initDropdowns(document);
379
+ initThemeToggle(document);
380
+ initTabsStrips(document);
381
+ document.addEventListener('astro:page-load', () => {
382
+ initDropdowns(document);
383
+ initThemeToggle(document);
384
+ initTabsStrips(document);
385
+ });
386
+ </script>