@writedocs/generator 0.13.4 → 0.13.5

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 (86) hide show
  1. package/README.md +28 -28
  2. package/astro.config.mjs +645 -645
  3. package/bin/writedocs.js +356 -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 +203 -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 +268 -268
  11. package/src/cli/exit-when-flushed.js +42 -42
  12. package/src/cli/generate-api-pages.js +507 -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 +69 -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 +203 -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 +408 -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.ts +2509 -2509
  48. package/src/lib/config.ts +1316 -1316
  49. package/src/lib/consent.js +108 -108
  50. package/src/lib/content-store-reload-integration.js +101 -101
  51. package/src/lib/icon-data-dev.js +53 -53
  52. package/src/lib/image-size.js +152 -152
  53. package/src/lib/json-schema-descriptions.js +228 -228
  54. package/src/lib/link-check.js +544 -544
  55. package/src/lib/llms-index.ts +90 -90
  56. package/src/lib/mcp-dev-integration.js +65 -65
  57. package/src/lib/mcp-index.ts +102 -102
  58. package/src/lib/mintlify-convert.js +605 -605
  59. package/src/lib/moved-api-pages.js +49 -49
  60. package/src/lib/og-cards.js +33 -33
  61. package/src/lib/og-image.js +235 -235
  62. package/src/lib/openapi-dev-status.js +80 -80
  63. package/src/lib/openapi-reload-integration.js +193 -193
  64. package/src/lib/pages.js +312 -312
  65. package/src/lib/project-files-integration.js +116 -116
  66. package/src/lib/project-files.js +137 -137
  67. package/src/lib/rehype-base-path.js +62 -62
  68. package/src/lib/rehype-image-loading.js +71 -71
  69. package/src/lib/robots-txt.js +21 -21
  70. package/src/lib/search-scope.js +44 -44
  71. package/src/lib/selector-placement.js +50 -50
  72. package/src/lib/seo-tags.js +155 -155
  73. package/src/lib/shiki-code-block.js +7 -1
  74. package/src/lib/site-base.ts +27 -27
  75. package/src/lib/styles-asset-integration.js +291 -291
  76. package/src/lib/wdignore-cases.json +195 -195
  77. package/src/lib/wdignore.js +177 -177
  78. package/src/pages/404.astro +63 -63
  79. package/src/pages/[...slug].astro +1762 -1608
  80. package/src/pages/[...slug].md.ts +93 -93
  81. package/src/pages/llms-full.txt.ts +88 -88
  82. package/src/pages/og/[...slug].png.ts +63 -63
  83. package/src/scripts/mobile-menu.ts +80 -80
  84. package/src/scripts/search.ts +245 -245
  85. package/src/scripts/sidebar-scroll.ts +61 -61
  86. package/src/styles/global.css +40 -40
@@ -1,374 +1,374 @@
1
- ---
2
- // The "Copy page" split button - on by default, showing the options
3
- // writedocs.json's `contextMenu` leaves on (`options`, from
4
- // contextMenuOptions() in lib/config-schema.ts). With `copy`, a primary button
5
- // (always-visible "Copy page" action, copies this page's Markdown
6
- // straight to the clipboard on click - see initCopyPageMenu() in
7
- // [...slug].astro) plus a small caret-only button next to it that opens
8
- // a dropdown for the rest (View as Markdown, Open in ChatGPT/Claude/
9
- // Perplexity) - only the caret button is a .wd-dropdown-trigger, so only
10
- // clicking (or hovering, per the shared CSS) *it* opens the menu, not
11
- // the primary action next to it. The dropdown itself reuses the exact
12
- // .wd-dropdown/.wd-dropdown-trigger/.wd-dropdown-menu/
13
- // .wd-dropdown-menu-panel markup pattern BaseLayout.astro's topbar
14
- // selectors already use - open/close/outside-click/Escape all come free
15
- // from BaseLayout's initDropdowns(document), which queries `.wd-dropdown`
16
- // anywhere in the page, not just its own template. See BaseLayout.astro's
17
- // own comment on the :global() wrapping its copy of that CSS needed so
18
- // the rules reach markup rendered by a different component (this one).
19
- //
20
- // Rendered from [...slug].astro (see its own comment on where/when),
21
- // which passes in everything needed to build both same-origin links (the
22
- // .md route from [...slug].md.ts) and the external "Open in X" links
23
- // (which need an absolute URL - from writedocs.json's `domain` when it's
24
- // set, else from the page's own address in the browser; see
25
- // enabledAssistants below).
26
- // Without `copy`, the options get a labeled "Page options" trigger of their
27
- // own - or, when there's just one, that option is the button itself ("Open
28
- // in Claude"). With only `copy`, the primary button stands alone.
29
- //
30
- // The last three options connect AI tools to the site's MCP server (/mcp -
31
- // see docs/dev/docs/mcp.mdx): copy its address, or add it to Cursor or VS
32
- // Code through their install links (lib/mcp-links.js). [...slug].astro
33
- // leaves them out when writedocs.json turns `mcp` off.
34
- import { Icon } from 'astro-icon/components';
35
- import type { ContextMenuOption } from '../lib/config';
36
- import { mcpServerUrl, cursorInstallLink, vscodeInstallLink } from '../lib/mcp-links.js';
37
- import { siteHref } from '../lib/site-base';
38
-
39
- interface Props {
40
- currentPath: string; // e.g. "/" or "/guides/foo/" - see hrefForSlug() in [...slug].astro
41
- // {domain}{basePath}, or null without a `domain` (resolveSiteUrl()).
42
- siteUrl: string | null;
43
- siteName: string;
44
- options: ContextMenuOption[];
45
- }
46
-
47
- const { currentPath, siteUrl, siteName, options } = Astro.props as Props;
48
-
49
- // The [...slug].md.ts route this page is also served at - same
50
- // normalizeEntryId()-driven convention that file uses to build its own
51
- // getStaticPaths params ("/" -> "index.md", everything else -> its own
52
- // slug with a literal ".md" appended instead of the trailing slash).
53
- const mdPath = currentPath === '/' ? '/index.md' : `${currentPath.replace(/\/$/, '')}.md`;
54
- const mdAbsoluteUrl = siteUrl ? `${siteUrl}${mdPath}` : null;
55
- // The .md's address as the page links it - with the basePath (lib/site-base.ts).
56
- const mdHref = siteHref(mdPath);
57
- const mcpUrl = siteUrl ? mcpServerUrl(siteUrl) : null;
58
-
59
- // Well-known query-string conventions for starting a new conversation
60
- // pre-seeded with a prompt (not an official API for any of the three -
61
- // just the same `?q=`/`/new?q=`/`/search?q=` pattern each already
62
- // supports for search-engine-style deep links). Pointing the prompt at
63
- // this page's own .md URL rather than pasting the page content directly
64
- // into the query string keeps the link itself short and lets the
65
- // assistant fetch the current content instead of a snapshot baked into
66
- // a bookmarked/shared link.
67
- const promptFor = (url: string) => `Read ${url} so you can answer questions about it.`;
68
-
69
- // `base` + the URL-encoded prompt is the link; `home` is where it goes
70
- // before the page script has filled the prompt in (see below).
71
- const assistants = [
72
- { id: 'chatgpt' as const, label: 'ChatGPT', icon: 'simple-icons:openai', base: 'https://chatgpt.com/?q=', home: 'https://chatgpt.com/' },
73
- { id: 'claude' as const, label: 'Claude', icon: 'simple-icons:claude', base: 'https://claude.ai/new?q=', home: 'https://claude.ai/new' },
74
- { id: 'perplexity' as const, label: 'Perplexity', icon: 'simple-icons:perplexity', base: 'https://www.perplexity.ai/search?q=', home: 'https://www.perplexity.ai/' },
75
- ];
76
- const editors = [
77
- { id: 'cursor' as const, label: 'Cursor', icon: 'simple-icons:cursor', link: cursorInstallLink, home: 'https://docs.cursor.com/context/mcp' },
78
- { id: 'vscode' as const, label: 'VS Code', icon: 'simple-icons:visualstudiocode', link: vscodeInstallLink, home: 'https://code.visualstudio.com/docs/copilot/chat/mcp-servers' },
79
- ];
80
-
81
- // Every link needs an absolute URL - the page's .md for an assistant, the
82
- // MCP server for an editor. With a `domain` it's known at build time and the
83
- // link is complete in the HTML. Without one, the page script ([...slug].astro)
84
- // completes it from the address the page is actually served from, using the
85
- // data-* attributes below; until then the link goes to the tool's own page.
86
- type Item = {
87
- id: ContextMenuOption;
88
- title: string;
89
- desc: string;
90
- icon: string;
91
- group: 'page' | 'mcp';
92
- href?: string;
93
- newTab?: boolean;
94
- attrs?: Record<string, string | undefined>;
95
- };
96
- const items: Item[] = [];
97
- if (options.includes('view')) {
98
- items.push({ id: 'view', title: 'View as Markdown', desc: 'View this page as plain text', icon: 'lucide:external-link', group: 'page', href: mdHref, newTab: true });
99
- }
100
- for (const a of assistants.filter((a) => options.includes(a.id))) {
101
- items.push({
102
- id: a.id,
103
- title: `Open in ${a.label}`,
104
- desc: 'Ask questions about this page',
105
- icon: a.icon,
106
- group: 'page',
107
- href: mdAbsoluteUrl ? a.base + encodeURIComponent(promptFor(mdAbsoluteUrl)) : a.home,
108
- newTab: true,
109
- attrs: mdAbsoluteUrl ? undefined : { 'data-ask-base': a.base, 'data-md-path': mdHref },
110
- });
111
- }
112
- if (options.includes('mcp')) {
113
- items.push({ id: 'mcp', title: 'Copy MCP server URL', desc: 'Connect AI tools to these docs', icon: 'simple-icons:modelcontextprotocol', group: 'mcp', attrs: { 'data-copy-mcp': mcpUrl ?? '' } });
114
- }
115
- for (const e of editors.filter((e) => options.includes(e.id))) {
116
- items.push({
117
- id: e.id,
118
- title: `Connect to ${e.label}`,
119
- desc: `Use these docs in ${e.label}`,
120
- icon: e.icon,
121
- group: 'mcp',
122
- // An editor's own link scheme (cursor://, vscode:) - opens the app, not a tab.
123
- href: mcpUrl ? e.link(siteName, mcpUrl) : e.home,
124
- attrs: mcpUrl ? undefined : { 'data-mcp-install': e.id, 'data-mcp-name': siteName },
125
- });
126
- }
127
-
128
- const showCopy = options.includes('copy');
129
- // One option and no "Copy page": that option is the button.
130
- const single = !showCopy && items.length === 1 ? items[0] : null;
131
- const hasDropdown = items.length > 0 && !single;
132
- ---
133
- {(showCopy || items.length > 0) && (
134
- <div class="wd-copy-page-split" data-pagefind-ignore="all" data-markdown-ignore>
135
- {showCopy && (
136
- <button type="button" class:list={['wd-copy-page-primary', { 'wd-copy-page-alone': !hasDropdown }]} data-copy-page data-md-path={mdHref} aria-label="Copy page as Markdown">
137
- <Icon name="lucide:copy" class="wd-copy-page-icon" />
138
- <span class="wd-copy-page-primary-label">Copy page</span>
139
- </button>
140
- )}
141
- {single && (single.href ? (
142
- <a class="wd-copy-page-primary wd-copy-page-alone" href={single.href} target={single.newTab ? '_blank' : undefined} rel={single.newTab ? 'noopener' : undefined} {...single.attrs}>
143
- <Icon name={single.icon} class="wd-copy-page-icon" />
144
- <span class="wd-copy-page-primary-label">{single.title}</span>
145
- </a>
146
- ) : (
147
- <button type="button" class="wd-copy-page-primary wd-copy-page-alone" {...single.attrs}>
148
- <Icon name={single.icon} class="wd-copy-page-icon" />
149
- <span class="wd-copy-page-primary-label">{single.title}</span>
150
- </button>
151
- ))}
152
- {hasDropdown && (
153
- <div class="wd-dropdown wd-copy-page">
154
- <button type="button" class:list={['wd-dropdown-trigger', 'wd-copy-page-caret-trigger', { 'wd-copy-page-labeled-trigger': !showCopy }]} aria-expanded="false" aria-label={showCopy ? 'More copy options' : 'Page options'}>
155
- {!showCopy && (
156
- <>
157
- <Icon name="lucide:sparkles" class="wd-copy-page-icon" />
158
- <span class="wd-copy-page-primary-label">Page options</span>
159
- </>
160
- )}
161
- <svg class="wd-dropdown-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
162
- <path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
163
- </svg>
164
- </button>
165
- <div class="wd-dropdown-menu wd-copy-page-menu">
166
- <div class="wd-dropdown-menu-panel wd-copy-page-menu-panel">
167
- {items.map((item, i) => (
168
- <>
169
- {i > 0 && item.group !== items[i - 1].group && <hr class="wd-copy-page-divider" />}
170
- {item.href ? (
171
- <a class="wd-copy-page-item" href={item.href} target={item.newTab ? '_blank' : undefined} rel={item.newTab ? 'noopener' : undefined} {...item.attrs}>
172
- <Icon name={item.icon} class="wd-copy-page-icon" />
173
- <span class="wd-copy-page-item-text">
174
- <span class="wd-copy-page-item-title">{item.title}</span>
175
- <span class="wd-copy-page-item-desc">{item.desc}</span>
176
- </span>
177
- </a>
178
- ) : (
179
- <button type="button" class="wd-copy-page-item" {...item.attrs}>
180
- <Icon name={item.icon} class="wd-copy-page-icon" />
181
- <span class="wd-copy-page-item-text">
182
- <span class="wd-copy-page-item-title">{item.title}</span>
183
- <span class="wd-copy-page-item-desc">{item.desc}</span>
184
- </span>
185
- </button>
186
- )}
187
- </>
188
- ))}
189
- </div>
190
- </div>
191
- </div>
192
- )}
193
- </div>
194
- )}
195
-
196
- <style>
197
- /* The split button: a primary "Copy page" action (always visible,
198
- copies on click - see initCopyPageMenu() in [...slug].astro) and a
199
- small caret-only button next to it that opens the rest (View as
200
- Markdown, Open in X). Each button gets its own half of the shared
201
- border-radius (left corners on the primary button, right corners on
202
- the caret button) rather than `overflow: hidden` on the wrapper -
203
- overflow: hidden was tried first and clips more than intended: the
204
- dropdown menu itself is an absolutely-positioned descendant of
205
- .wd-dropdown, which lives inside this wrapper, so clipping the
206
- wrapper's overflow silently clipped the open menu away too (the
207
- caret still visibly rotated on hover/open, since that's a transform
208
- on the caret itself, not the menu - only the menu's own visibility
209
- was affected, which is what made this look like "nothing happens"
210
- rather than an obvious rendering glitch). */
211
- .wd-copy-page-split {
212
- display: flex;
213
- align-items: stretch;
214
- border: 1px solid var(--wd-border);
215
- border-radius: 0.4rem;
216
- flex-shrink: 0;
217
- /* Right-aligned on its own line too (a long title on a phone sends it
218
- below the title) - its menu opens leftwards, and stays on screen. */
219
- margin-left: auto;
220
- }
221
- /* .wd-copy-page is this instance's own class on the .wd-dropdown div
222
- wrapping the caret button + menu (see BaseLayout.astro's shared
223
- .wd-dropdown rule for `position: relative`, which still applies
224
- alongside this). .wd-copy-page-split's `align-items: stretch` above
225
- stretches this div's own height to match the primary button next to
226
- it, but that alone doesn't stretch the *caret button inside it* -
227
- .wd-dropdown is a plain block div, not a flex container, so its
228
- child sizes itself independently and just sits at the top of the
229
- now-taller div, which is what made the arrow look vertically
230
- off-center against the primary button. Making this div a flex
231
- container too (with its own stretch) propagates the height down to
232
- the button, which centers the svg within it via the shared
233
- .wd-dropdown-trigger rule's own align-items: center. */
234
- .wd-copy-page {
235
- display: flex;
236
- align-items: stretch;
237
- }
238
- .wd-copy-page-primary {
239
- display: flex;
240
- align-items: center;
241
- gap: 0.35rem;
242
- padding: 0.35rem 0.65rem;
243
- border: none;
244
- border-radius: 0.35rem 0 0 0.35rem;
245
- background: none;
246
- cursor: pointer;
247
- color: var(--wd-text-muted);
248
- font-size: 0.85rem;
249
- font-weight: 500;
250
- font-family: inherit;
251
- }
252
- .wd-copy-page-primary:hover {
253
- color: var(--wd-text);
254
- background: var(--wd-surface);
255
- }
256
- /* Toggled by initCopyPageMenu() for ~1.5s after a successful copy -
257
- the label itself swaps to "Copied!" via JS (not CSS content, so a
258
- screen reader announces it), this just tints icon+text green to
259
- match. */
260
- .wd-copy-page-primary.wd-copy-page-copied {
261
- color: #16a34a;
262
- }
263
- /* Overrides the shared .wd-dropdown-trigger base rule (BaseLayout.astro)
264
- down to an icon-only square button - no padding/border of its own
265
- beyond the divider line, and only the right corners rounded (to
266
- match .wd-copy-page-split's own outer radius on that side - see the
267
- comment above on why the wrapper itself no longer clips to its
268
- radius via overflow: hidden). */
269
- .wd-copy-page-caret-trigger {
270
- padding: 0.35rem 0.5rem;
271
- border: none;
272
- border-left: 1px solid var(--wd-border);
273
- border-radius: 0 0.35rem 0.35rem 0;
274
- }
275
- /* Only one of the two halves: it gets all four corners (and, for the
276
- trigger, no divider line and a label like the primary button's). */
277
- .wd-copy-page-primary.wd-copy-page-alone {
278
- border-radius: 0.35rem;
279
- }
280
- /* The single-option button can be a link ("Open in Claude"). */
281
- a.wd-copy-page-primary {
282
- text-decoration: none;
283
- }
284
- /* Between the page's options and the MCP server's. */
285
- .wd-copy-page-divider {
286
- margin: 0.3rem 0.4rem;
287
- border: none;
288
- border-top: 1px solid var(--wd-border);
289
- }
290
- .wd-copy-page-caret-trigger.wd-copy-page-labeled-trigger {
291
- gap: 0.35rem;
292
- padding: 0.35rem 0.65rem;
293
- border-left: none;
294
- border-radius: 0.35rem;
295
- color: var(--wd-text-muted);
296
- font-size: 0.85rem;
297
- font-weight: 500;
298
- }
299
- .wd-copy-page-menu {
300
- left: auto;
301
- right: 0;
302
- }
303
- /* overflow: hidden here (in addition to .wd-copy-page-item below no
304
- longer overflowing its own box) is defensive belt-and-suspenders -
305
- keeps any future item's hover background from ever visibly poking
306
- past the panel's own rounded corners, the exact bug .wd-copy-page-item
307
- used to have. */
308
- .wd-copy-page-menu-panel {
309
- min-width: 260px;
310
- overflow: hidden;
311
- }
312
- .wd-copy-page-icon {
313
- width: 1em;
314
- height: 1em;
315
- flex-shrink: 0;
316
- }
317
- /* .wd-dropdown-menu a (BaseLayout.astro) is single-line only
318
- (align-items: center on one row of text) - these items need a
319
- title + description subtitle, so .wd-copy-page-item re-implements
320
- that layout instead (icon top-aligned next to a two-line text
321
- stack) rather than trying to make the shared single-line rule cover
322
- both shapes.
323
- No explicit `width` here - deliberately: this codebase doesn't set
324
- a global `box-sizing: border-box` reset (see the comment on
325
- Tailwind's preflight in src/styles/global.css), so a block-level
326
- element's default `width: auto` already correctly fills its
327
- container *net of* its own padding, while an explicit `width: 100%`
328
- would add that padding on top instead, overflowing past the
329
- container's edge - exactly what an earlier version of this rule did
330
- (visible as the hover background bleeding out past the panel's
331
- rounded corner on hover). Leave width unset rather than reaching for
332
- `box-sizing: border-box` here alone, which would just be one rule
333
- quietly relying on a codebase-wide convention it doesn't establish. */
334
- .wd-copy-page-item {
335
- display: flex;
336
- align-items: flex-start;
337
- gap: 0.6rem;
338
- padding: 0.5rem 0.6rem;
339
- border: none;
340
- border-radius: 0.35rem;
341
- background: none;
342
- text-decoration: none;
343
- color: var(--wd-text);
344
- font-family: inherit;
345
- text-align: left;
346
- cursor: pointer;
347
- }
348
- /* A button option ("Copy MCP server URL") fills the row like the links
349
- do - a button sizes to its content otherwise. */
350
- button.wd-copy-page-item {
351
- width: 100%;
352
- box-sizing: border-box;
353
- }
354
- .wd-copy-page-item:hover {
355
- background: var(--wd-surface);
356
- }
357
- .wd-copy-page-item .wd-copy-page-icon {
358
- margin-top: 0.15rem;
359
- color: var(--wd-text-muted);
360
- }
361
- .wd-copy-page-item-text {
362
- display: flex;
363
- flex-direction: column;
364
- gap: 0.1rem;
365
- }
366
- .wd-copy-page-item-title {
367
- font-size: 0.86rem;
368
- font-weight: 500;
369
- }
370
- .wd-copy-page-item-desc {
371
- font-size: 0.76rem;
372
- color: var(--wd-text-muted);
373
- }
374
- </style>
1
+ ---
2
+ // The "Copy page" split button - on by default, showing the options
3
+ // writedocs.json's `contextMenu` leaves on (`options`, from
4
+ // contextMenuOptions() in lib/config-schema.ts). With `copy`, a primary button
5
+ // (always-visible "Copy page" action, copies this page's Markdown
6
+ // straight to the clipboard on click - see initCopyPageMenu() in
7
+ // [...slug].astro) plus a small caret-only button next to it that opens
8
+ // a dropdown for the rest (View as Markdown, Open in ChatGPT/Claude/
9
+ // Perplexity) - only the caret button is a .wd-dropdown-trigger, so only
10
+ // clicking (or hovering, per the shared CSS) *it* opens the menu, not
11
+ // the primary action next to it. The dropdown itself reuses the exact
12
+ // .wd-dropdown/.wd-dropdown-trigger/.wd-dropdown-menu/
13
+ // .wd-dropdown-menu-panel markup pattern BaseLayout.astro's topbar
14
+ // selectors already use - open/close/outside-click/Escape all come free
15
+ // from BaseLayout's initDropdowns(document), which queries `.wd-dropdown`
16
+ // anywhere in the page, not just its own template. See BaseLayout.astro's
17
+ // own comment on the :global() wrapping its copy of that CSS needed so
18
+ // the rules reach markup rendered by a different component (this one).
19
+ //
20
+ // Rendered from [...slug].astro (see its own comment on where/when),
21
+ // which passes in everything needed to build both same-origin links (the
22
+ // .md route from [...slug].md.ts) and the external "Open in X" links
23
+ // (which need an absolute URL - from writedocs.json's `domain` when it's
24
+ // set, else from the page's own address in the browser; see
25
+ // enabledAssistants below).
26
+ // Without `copy`, the options get a labeled "Page options" trigger of their
27
+ // own - or, when there's just one, that option is the button itself ("Open
28
+ // in Claude"). With only `copy`, the primary button stands alone.
29
+ //
30
+ // The last three options connect AI tools to the site's MCP server (/mcp -
31
+ // see docs/dev/docs/mcp.mdx): copy its address, or add it to Cursor or VS
32
+ // Code through their install links (lib/mcp-links.js). [...slug].astro
33
+ // leaves them out when writedocs.json turns `mcp` off.
34
+ import { Icon } from 'astro-icon/components';
35
+ import type { ContextMenuOption } from '../lib/config';
36
+ import { mcpServerUrl, cursorInstallLink, vscodeInstallLink } from '../lib/mcp-links.js';
37
+ import { siteHref } from '../lib/site-base';
38
+
39
+ interface Props {
40
+ currentPath: string; // e.g. "/" or "/guides/foo/" - see hrefForSlug() in [...slug].astro
41
+ // {domain}{basePath}, or null without a `domain` (resolveSiteUrl()).
42
+ siteUrl: string | null;
43
+ siteName: string;
44
+ options: ContextMenuOption[];
45
+ }
46
+
47
+ const { currentPath, siteUrl, siteName, options } = Astro.props as Props;
48
+
49
+ // The [...slug].md.ts route this page is also served at - same
50
+ // normalizeEntryId()-driven convention that file uses to build its own
51
+ // getStaticPaths params ("/" -> "index.md", everything else -> its own
52
+ // slug with a literal ".md" appended instead of the trailing slash).
53
+ const mdPath = currentPath === '/' ? '/index.md' : `${currentPath.replace(/\/$/, '')}.md`;
54
+ const mdAbsoluteUrl = siteUrl ? `${siteUrl}${mdPath}` : null;
55
+ // The .md's address as the page links it - with the basePath (lib/site-base.ts).
56
+ const mdHref = siteHref(mdPath);
57
+ const mcpUrl = siteUrl ? mcpServerUrl(siteUrl) : null;
58
+
59
+ // Well-known query-string conventions for starting a new conversation
60
+ // pre-seeded with a prompt (not an official API for any of the three -
61
+ // just the same `?q=`/`/new?q=`/`/search?q=` pattern each already
62
+ // supports for search-engine-style deep links). Pointing the prompt at
63
+ // this page's own .md URL rather than pasting the page content directly
64
+ // into the query string keeps the link itself short and lets the
65
+ // assistant fetch the current content instead of a snapshot baked into
66
+ // a bookmarked/shared link.
67
+ const promptFor = (url: string) => `Read ${url} so you can answer questions about it.`;
68
+
69
+ // `base` + the URL-encoded prompt is the link; `home` is where it goes
70
+ // before the page script has filled the prompt in (see below).
71
+ const assistants = [
72
+ { id: 'chatgpt' as const, label: 'ChatGPT', icon: 'simple-icons:openai', base: 'https://chatgpt.com/?q=', home: 'https://chatgpt.com/' },
73
+ { id: 'claude' as const, label: 'Claude', icon: 'simple-icons:claude', base: 'https://claude.ai/new?q=', home: 'https://claude.ai/new' },
74
+ { id: 'perplexity' as const, label: 'Perplexity', icon: 'simple-icons:perplexity', base: 'https://www.perplexity.ai/search?q=', home: 'https://www.perplexity.ai/' },
75
+ ];
76
+ const editors = [
77
+ { id: 'cursor' as const, label: 'Cursor', icon: 'simple-icons:cursor', link: cursorInstallLink, home: 'https://docs.cursor.com/context/mcp' },
78
+ { id: 'vscode' as const, label: 'VS Code', icon: 'simple-icons:visualstudiocode', link: vscodeInstallLink, home: 'https://code.visualstudio.com/docs/copilot/chat/mcp-servers' },
79
+ ];
80
+
81
+ // Every link needs an absolute URL - the page's .md for an assistant, the
82
+ // MCP server for an editor. With a `domain` it's known at build time and the
83
+ // link is complete in the HTML. Without one, the page script ([...slug].astro)
84
+ // completes it from the address the page is actually served from, using the
85
+ // data-* attributes below; until then the link goes to the tool's own page.
86
+ type Item = {
87
+ id: ContextMenuOption;
88
+ title: string;
89
+ desc: string;
90
+ icon: string;
91
+ group: 'page' | 'mcp';
92
+ href?: string;
93
+ newTab?: boolean;
94
+ attrs?: Record<string, string | undefined>;
95
+ };
96
+ const items: Item[] = [];
97
+ if (options.includes('view')) {
98
+ items.push({ id: 'view', title: 'View as Markdown', desc: 'View this page as plain text', icon: 'lucide:external-link', group: 'page', href: mdHref, newTab: true });
99
+ }
100
+ for (const a of assistants.filter((a) => options.includes(a.id))) {
101
+ items.push({
102
+ id: a.id,
103
+ title: `Open in ${a.label}`,
104
+ desc: 'Ask questions about this page',
105
+ icon: a.icon,
106
+ group: 'page',
107
+ href: mdAbsoluteUrl ? a.base + encodeURIComponent(promptFor(mdAbsoluteUrl)) : a.home,
108
+ newTab: true,
109
+ attrs: mdAbsoluteUrl ? undefined : { 'data-ask-base': a.base, 'data-md-path': mdHref },
110
+ });
111
+ }
112
+ if (options.includes('mcp')) {
113
+ items.push({ id: 'mcp', title: 'Copy MCP server URL', desc: 'Connect AI tools to these docs', icon: 'simple-icons:modelcontextprotocol', group: 'mcp', attrs: { 'data-copy-mcp': mcpUrl ?? '' } });
114
+ }
115
+ for (const e of editors.filter((e) => options.includes(e.id))) {
116
+ items.push({
117
+ id: e.id,
118
+ title: `Connect to ${e.label}`,
119
+ desc: `Use these docs in ${e.label}`,
120
+ icon: e.icon,
121
+ group: 'mcp',
122
+ // An editor's own link scheme (cursor://, vscode:) - opens the app, not a tab.
123
+ href: mcpUrl ? e.link(siteName, mcpUrl) : e.home,
124
+ attrs: mcpUrl ? undefined : { 'data-mcp-install': e.id, 'data-mcp-name': siteName },
125
+ });
126
+ }
127
+
128
+ const showCopy = options.includes('copy');
129
+ // One option and no "Copy page": that option is the button.
130
+ const single = !showCopy && items.length === 1 ? items[0] : null;
131
+ const hasDropdown = items.length > 0 && !single;
132
+ ---
133
+ {(showCopy || items.length > 0) && (
134
+ <div class="wd-copy-page-split" data-pagefind-ignore="all" data-markdown-ignore>
135
+ {showCopy && (
136
+ <button type="button" class:list={['wd-copy-page-primary', { 'wd-copy-page-alone': !hasDropdown }]} data-copy-page data-md-path={mdHref} aria-label="Copy page as Markdown">
137
+ <Icon name="lucide:copy" class="wd-copy-page-icon" />
138
+ <span class="wd-copy-page-primary-label">Copy page</span>
139
+ </button>
140
+ )}
141
+ {single && (single.href ? (
142
+ <a class="wd-copy-page-primary wd-copy-page-alone" href={single.href} target={single.newTab ? '_blank' : undefined} rel={single.newTab ? 'noopener' : undefined} {...single.attrs}>
143
+ <Icon name={single.icon} class="wd-copy-page-icon" />
144
+ <span class="wd-copy-page-primary-label">{single.title}</span>
145
+ </a>
146
+ ) : (
147
+ <button type="button" class="wd-copy-page-primary wd-copy-page-alone" {...single.attrs}>
148
+ <Icon name={single.icon} class="wd-copy-page-icon" />
149
+ <span class="wd-copy-page-primary-label">{single.title}</span>
150
+ </button>
151
+ ))}
152
+ {hasDropdown && (
153
+ <div class="wd-dropdown wd-copy-page">
154
+ <button type="button" class:list={['wd-dropdown-trigger', 'wd-copy-page-caret-trigger', { 'wd-copy-page-labeled-trigger': !showCopy }]} aria-expanded="false" aria-label={showCopy ? 'More copy options' : 'Page options'}>
155
+ {!showCopy && (
156
+ <>
157
+ <Icon name="lucide:sparkles" class="wd-copy-page-icon" />
158
+ <span class="wd-copy-page-primary-label">Page options</span>
159
+ </>
160
+ )}
161
+ <svg class="wd-dropdown-caret" width="10" height="10" viewBox="0 0 10 10" aria-hidden="true">
162
+ <path d="M2 3.5L5 6.5L8 3.5" stroke="currentColor" stroke-width="1.4" fill="none" stroke-linecap="round" stroke-linejoin="round" />
163
+ </svg>
164
+ </button>
165
+ <div class="wd-dropdown-menu wd-copy-page-menu">
166
+ <div class="wd-dropdown-menu-panel wd-copy-page-menu-panel">
167
+ {items.map((item, i) => (
168
+ <>
169
+ {i > 0 && item.group !== items[i - 1].group && <hr class="wd-copy-page-divider" />}
170
+ {item.href ? (
171
+ <a class="wd-copy-page-item" href={item.href} target={item.newTab ? '_blank' : undefined} rel={item.newTab ? 'noopener' : undefined} {...item.attrs}>
172
+ <Icon name={item.icon} class="wd-copy-page-icon" />
173
+ <span class="wd-copy-page-item-text">
174
+ <span class="wd-copy-page-item-title">{item.title}</span>
175
+ <span class="wd-copy-page-item-desc">{item.desc}</span>
176
+ </span>
177
+ </a>
178
+ ) : (
179
+ <button type="button" class="wd-copy-page-item" {...item.attrs}>
180
+ <Icon name={item.icon} class="wd-copy-page-icon" />
181
+ <span class="wd-copy-page-item-text">
182
+ <span class="wd-copy-page-item-title">{item.title}</span>
183
+ <span class="wd-copy-page-item-desc">{item.desc}</span>
184
+ </span>
185
+ </button>
186
+ )}
187
+ </>
188
+ ))}
189
+ </div>
190
+ </div>
191
+ </div>
192
+ )}
193
+ </div>
194
+ )}
195
+
196
+ <style>
197
+ /* The split button: a primary "Copy page" action (always visible,
198
+ copies on click - see initCopyPageMenu() in [...slug].astro) and a
199
+ small caret-only button next to it that opens the rest (View as
200
+ Markdown, Open in X). Each button gets its own half of the shared
201
+ border-radius (left corners on the primary button, right corners on
202
+ the caret button) rather than `overflow: hidden` on the wrapper -
203
+ overflow: hidden was tried first and clips more than intended: the
204
+ dropdown menu itself is an absolutely-positioned descendant of
205
+ .wd-dropdown, which lives inside this wrapper, so clipping the
206
+ wrapper's overflow silently clipped the open menu away too (the
207
+ caret still visibly rotated on hover/open, since that's a transform
208
+ on the caret itself, not the menu - only the menu's own visibility
209
+ was affected, which is what made this look like "nothing happens"
210
+ rather than an obvious rendering glitch). */
211
+ .wd-copy-page-split {
212
+ display: flex;
213
+ align-items: stretch;
214
+ border: 1px solid var(--wd-border);
215
+ border-radius: 0.4rem;
216
+ flex-shrink: 0;
217
+ /* Right-aligned on its own line too (a long title on a phone sends it
218
+ below the title) - its menu opens leftwards, and stays on screen. */
219
+ margin-left: auto;
220
+ }
221
+ /* .wd-copy-page is this instance's own class on the .wd-dropdown div
222
+ wrapping the caret button + menu (see BaseLayout.astro's shared
223
+ .wd-dropdown rule for `position: relative`, which still applies
224
+ alongside this). .wd-copy-page-split's `align-items: stretch` above
225
+ stretches this div's own height to match the primary button next to
226
+ it, but that alone doesn't stretch the *caret button inside it* -
227
+ .wd-dropdown is a plain block div, not a flex container, so its
228
+ child sizes itself independently and just sits at the top of the
229
+ now-taller div, which is what made the arrow look vertically
230
+ off-center against the primary button. Making this div a flex
231
+ container too (with its own stretch) propagates the height down to
232
+ the button, which centers the svg within it via the shared
233
+ .wd-dropdown-trigger rule's own align-items: center. */
234
+ .wd-copy-page {
235
+ display: flex;
236
+ align-items: stretch;
237
+ }
238
+ .wd-copy-page-primary {
239
+ display: flex;
240
+ align-items: center;
241
+ gap: 0.35rem;
242
+ padding: 0.35rem 0.65rem;
243
+ border: none;
244
+ border-radius: 0.35rem 0 0 0.35rem;
245
+ background: none;
246
+ cursor: pointer;
247
+ color: var(--wd-text-muted);
248
+ font-size: 0.85rem;
249
+ font-weight: 500;
250
+ font-family: inherit;
251
+ }
252
+ .wd-copy-page-primary:hover {
253
+ color: var(--wd-text);
254
+ background: var(--wd-surface);
255
+ }
256
+ /* Toggled by initCopyPageMenu() for ~1.5s after a successful copy -
257
+ the label itself swaps to "Copied!" via JS (not CSS content, so a
258
+ screen reader announces it), this just tints icon+text green to
259
+ match. */
260
+ .wd-copy-page-primary.wd-copy-page-copied {
261
+ color: #16a34a;
262
+ }
263
+ /* Overrides the shared .wd-dropdown-trigger base rule (BaseLayout.astro)
264
+ down to an icon-only square button - no padding/border of its own
265
+ beyond the divider line, and only the right corners rounded (to
266
+ match .wd-copy-page-split's own outer radius on that side - see the
267
+ comment above on why the wrapper itself no longer clips to its
268
+ radius via overflow: hidden). */
269
+ .wd-copy-page-caret-trigger {
270
+ padding: 0.35rem 0.5rem;
271
+ border: none;
272
+ border-left: 1px solid var(--wd-border);
273
+ border-radius: 0 0.35rem 0.35rem 0;
274
+ }
275
+ /* Only one of the two halves: it gets all four corners (and, for the
276
+ trigger, no divider line and a label like the primary button's). */
277
+ .wd-copy-page-primary.wd-copy-page-alone {
278
+ border-radius: 0.35rem;
279
+ }
280
+ /* The single-option button can be a link ("Open in Claude"). */
281
+ a.wd-copy-page-primary {
282
+ text-decoration: none;
283
+ }
284
+ /* Between the page's options and the MCP server's. */
285
+ .wd-copy-page-divider {
286
+ margin: 0.3rem 0.4rem;
287
+ border: none;
288
+ border-top: 1px solid var(--wd-border);
289
+ }
290
+ .wd-copy-page-caret-trigger.wd-copy-page-labeled-trigger {
291
+ gap: 0.35rem;
292
+ padding: 0.35rem 0.65rem;
293
+ border-left: none;
294
+ border-radius: 0.35rem;
295
+ color: var(--wd-text-muted);
296
+ font-size: 0.85rem;
297
+ font-weight: 500;
298
+ }
299
+ .wd-copy-page-menu {
300
+ left: auto;
301
+ right: 0;
302
+ }
303
+ /* overflow: hidden here (in addition to .wd-copy-page-item below no
304
+ longer overflowing its own box) is defensive belt-and-suspenders -
305
+ keeps any future item's hover background from ever visibly poking
306
+ past the panel's own rounded corners, the exact bug .wd-copy-page-item
307
+ used to have. */
308
+ .wd-copy-page-menu-panel {
309
+ min-width: 260px;
310
+ overflow: hidden;
311
+ }
312
+ .wd-copy-page-icon {
313
+ width: 1em;
314
+ height: 1em;
315
+ flex-shrink: 0;
316
+ }
317
+ /* .wd-dropdown-menu a (BaseLayout.astro) is single-line only
318
+ (align-items: center on one row of text) - these items need a
319
+ title + description subtitle, so .wd-copy-page-item re-implements
320
+ that layout instead (icon top-aligned next to a two-line text
321
+ stack) rather than trying to make the shared single-line rule cover
322
+ both shapes.
323
+ No explicit `width` here - deliberately: this codebase doesn't set
324
+ a global `box-sizing: border-box` reset (see the comment on
325
+ Tailwind's preflight in src/styles/global.css), so a block-level
326
+ element's default `width: auto` already correctly fills its
327
+ container *net of* its own padding, while an explicit `width: 100%`
328
+ would add that padding on top instead, overflowing past the
329
+ container's edge - exactly what an earlier version of this rule did
330
+ (visible as the hover background bleeding out past the panel's
331
+ rounded corner on hover). Leave width unset rather than reaching for
332
+ `box-sizing: border-box` here alone, which would just be one rule
333
+ quietly relying on a codebase-wide convention it doesn't establish. */
334
+ .wd-copy-page-item {
335
+ display: flex;
336
+ align-items: flex-start;
337
+ gap: 0.6rem;
338
+ padding: 0.5rem 0.6rem;
339
+ border: none;
340
+ border-radius: 0.35rem;
341
+ background: none;
342
+ text-decoration: none;
343
+ color: var(--wd-text);
344
+ font-family: inherit;
345
+ text-align: left;
346
+ cursor: pointer;
347
+ }
348
+ /* A button option ("Copy MCP server URL") fills the row like the links
349
+ do - a button sizes to its content otherwise. */
350
+ button.wd-copy-page-item {
351
+ width: 100%;
352
+ box-sizing: border-box;
353
+ }
354
+ .wd-copy-page-item:hover {
355
+ background: var(--wd-surface);
356
+ }
357
+ .wd-copy-page-item .wd-copy-page-icon {
358
+ margin-top: 0.15rem;
359
+ color: var(--wd-text-muted);
360
+ }
361
+ .wd-copy-page-item-text {
362
+ display: flex;
363
+ flex-direction: column;
364
+ gap: 0.1rem;
365
+ }
366
+ .wd-copy-page-item-title {
367
+ font-size: 0.86rem;
368
+ font-weight: 500;
369
+ }
370
+ .wd-copy-page-item-desc {
371
+ font-size: 0.76rem;
372
+ color: var(--wd-text-muted);
373
+ }
374
+ </style>