@writedocs/generator 0.13.4 → 0.14.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 (89) hide show
  1. package/README.md +28 -28
  2. package/astro.config.mjs +645 -645
  3. package/bin/writedocs.js +359 -356
  4. package/package.json +99 -99
  5. package/src/cli/base-path-layout.js +44 -44
  6. package/src/cli/build-auth.js +135 -135
  7. package/src/cli/build.js +223 -203
  8. package/src/cli/check-built-styles.js +41 -41
  9. package/src/cli/convert.js +124 -124
  10. package/src/cli/dev.js +269 -268
  11. package/src/cli/exit-when-flushed.js +42 -42
  12. package/src/cli/generate-api-pages.js +509 -507
  13. package/src/cli/og-image-worker.js +20 -20
  14. package/src/cli/og-images.js +70 -70
  15. package/src/cli/page-list-watch.js +71 -69
  16. package/src/cli/run-astro.js +97 -97
  17. package/src/cli/run-pagefind.js +154 -154
  18. package/src/cli/write-mcp-files.js +103 -103
  19. package/src/cli/write-redirects-file.js +158 -158
  20. package/src/components/ApiReferencePanel.astro +1792 -1792
  21. package/src/components/AppIcon.astro +51 -51
  22. package/src/components/Card.astro +193 -193
  23. package/src/components/CodeGroup.astro +63 -39
  24. package/src/components/CopyPageMenu.astro +374 -374
  25. package/src/components/Hint.astro +188 -188
  26. package/src/components/Icon.astro +72 -72
  27. package/src/components/Image.astro +165 -165
  28. package/src/components/Tile.astro +67 -67
  29. package/src/components/Video.astro +137 -137
  30. package/src/content.config.ts +219 -203
  31. package/src/layout/BaseLayout.astro +908 -908
  32. package/src/layout/components/AnalyticsScripts.astro +49 -49
  33. package/src/layout/components/Breadcrumbs.astro +98 -98
  34. package/src/layout/components/ConsentBanner.astro +119 -119
  35. package/src/layout/components/MobileMenu.astro +225 -225
  36. package/src/layout/components/NavTree.astro +422 -408
  37. package/src/layout/components/Sidebar.astro +232 -232
  38. package/src/layout/components/SiteFooter.astro +87 -87
  39. package/src/layout/components/TopBar.astro +386 -386
  40. package/src/layout/styles/base.css +332 -326
  41. package/src/layout/styles/mobile-menu.css +285 -285
  42. package/src/lib/agent-markdown.js +164 -164
  43. package/src/lib/asset-dimensions.js +89 -89
  44. package/src/lib/base-path.js +90 -90
  45. package/src/lib/cli-report.js +22 -22
  46. package/src/lib/code-line-numbers.js +13 -0
  47. package/src/lib/config-schema.js +12 -1
  48. package/src/lib/config-schema.ts +2523 -2509
  49. package/src/lib/config.ts +1331 -1316
  50. package/src/lib/consent.js +108 -108
  51. package/src/lib/content-check.js +4 -1
  52. package/src/lib/content-store-reload-integration.js +101 -101
  53. package/src/lib/drafts.js +186 -0
  54. package/src/lib/icon-data-dev.js +53 -53
  55. package/src/lib/image-size.js +152 -152
  56. package/src/lib/json-schema-descriptions.js +228 -228
  57. package/src/lib/link-check.js +553 -544
  58. package/src/lib/llms-index.ts +90 -90
  59. package/src/lib/mcp-dev-integration.js +65 -65
  60. package/src/lib/mcp-index.ts +102 -102
  61. package/src/lib/mintlify-convert.js +605 -605
  62. package/src/lib/moved-api-pages.js +49 -49
  63. package/src/lib/og-cards.js +33 -33
  64. package/src/lib/og-image.js +235 -235
  65. package/src/lib/openapi-dev-status.js +80 -80
  66. package/src/lib/openapi-reload-integration.js +193 -193
  67. package/src/lib/pages.js +346 -312
  68. package/src/lib/project-files-integration.js +116 -116
  69. package/src/lib/project-files.js +137 -137
  70. package/src/lib/rehype-base-path.js +62 -62
  71. package/src/lib/rehype-image-loading.js +71 -71
  72. package/src/lib/robots-txt.js +21 -21
  73. package/src/lib/search-scope.js +44 -44
  74. package/src/lib/selector-placement.js +50 -50
  75. package/src/lib/seo-tags.js +157 -155
  76. package/src/lib/shiki-code-block.js +7 -1
  77. package/src/lib/site-base.ts +27 -27
  78. package/src/lib/styles-asset-integration.js +291 -291
  79. package/src/lib/wdignore-cases.json +195 -195
  80. package/src/lib/wdignore.js +177 -177
  81. package/src/pages/404.astro +63 -63
  82. package/src/pages/[...slug].astro +1773 -1608
  83. package/src/pages/[...slug].md.ts +93 -93
  84. package/src/pages/llms-full.txt.ts +88 -88
  85. package/src/pages/og/[...slug].png.ts +63 -63
  86. package/src/scripts/mobile-menu.ts +80 -80
  87. package/src/scripts/search.ts +245 -245
  88. package/src/scripts/sidebar-scroll.ts +61 -61
  89. package/src/styles/global.css +40 -40
@@ -1,386 +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
- 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>
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>