@stainless-api/docs 0.1.0-beta.6 → 0.1.0-beta.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +486 -0
- package/README.md +1 -1
- package/eslint-suppressions.json +52 -0
- package/locals.d.ts +16 -0
- package/package.json +45 -40
- package/plugin/assets/languages/csharp.svg +1 -0
- package/plugin/buildAlgoliaIndex.ts +32 -7
- package/plugin/cms/server.ts +130 -58
- package/plugin/cms/sidebar-builder.ts +7 -26
- package/plugin/cms/worker.ts +83 -5
- package/plugin/components/MethodDescription.tsx +54 -0
- package/plugin/components/SDKSelect.astro +7 -87
- package/plugin/components/SnippetCode.tsx +53 -8
- package/plugin/components/search/SearchAlgolia.astro +14 -26
- package/plugin/components/search/SearchIsland.tsx +38 -24
- package/plugin/create-playground.shim.tsx +3 -0
- package/plugin/generateAPIReferenceLink.ts +2 -2
- package/plugin/globalJs/ai-dropdown-options.ts +235 -0
- package/plugin/globalJs/code-snippets.ts +15 -8
- package/plugin/globalJs/copy.ts +81 -16
- package/plugin/globalJs/method-descriptions.ts +33 -0
- package/plugin/globalJs/navigation.ts +7 -4
- package/plugin/index.ts +179 -35
- package/plugin/languages.ts +5 -2
- package/plugin/loadPluginConfig.ts +121 -32
- package/plugin/middlewareBuilder/stainlessMiddleware.d.ts +1 -1
- package/plugin/react/Routing.tsx +208 -104
- package/plugin/referencePlaceholderUtils.ts +1 -1
- package/plugin/replaceSidebarPlaceholderMiddleware.ts +5 -1
- package/plugin/routes/Docs.astro +61 -83
- package/plugin/routes/Overview.astro +10 -16
- package/plugin/routes/markdown.ts +7 -7
- package/plugin/vendor/preview.worker.docs.js +19768 -17702
- package/plugin/vendor/templates/go.md +1 -1
- package/plugin/vendor/templates/python.md +1 -1
- package/resolveSrcFile.ts +10 -0
- package/scripts/vendor_deps.ts +5 -5
- package/shared/getSharedLogger.ts +15 -0
- package/shared/terminalUtils.ts +3 -0
- package/src/content.config.ts +9 -0
- package/stl-docs/components/AIDropdown.tsx +63 -0
- package/stl-docs/components/AiChatIsland.tsx +10 -0
- package/stl-docs/components/{content-panel/ContentBreadcrumbs.tsx → ContentBreadcrumbs.tsx} +10 -18
- package/stl-docs/components/Head.astro +16 -0
- package/stl-docs/components/Header.astro +6 -8
- package/stl-docs/components/PageFrame.astro +14 -0
- package/stl-docs/components/PageTitle.astro +82 -0
- package/stl-docs/components/TableOfContents.astro +34 -0
- package/stl-docs/components/ThemeSelect.astro +118 -136
- package/stl-docs/components/content-panel/ContentPanel.astro +16 -25
- package/stl-docs/components/headers/SplashMobileMenuToggle.astro +17 -1
- package/stl-docs/components/headers/StackedHeader.astro +29 -24
- package/stl-docs/components/icons/chat-gpt.tsx +17 -0
- package/stl-docs/components/icons/claude.tsx +10 -0
- package/stl-docs/components/icons/cursor.tsx +10 -0
- package/stl-docs/components/icons/gemini.tsx +19 -0
- package/stl-docs/components/icons/markdown.tsx +10 -0
- package/stl-docs/components/index.ts +1 -0
- package/stl-docs/components/mintlify-compat/Accordion.astro +7 -5
- package/stl-docs/components/mintlify-compat/AccordionGroup.astro +7 -3
- package/stl-docs/components/mintlify-compat/Columns.astro +40 -42
- package/stl-docs/components/mintlify-compat/Frame.astro +16 -18
- package/stl-docs/components/mintlify-compat/Step.astro +30 -32
- package/stl-docs/components/mintlify-compat/Steps.astro +8 -10
- package/stl-docs/components/mintlify-compat/callouts/Callout.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Check.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Danger.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Info.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Note.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Tip.astro +1 -1
- package/stl-docs/components/mintlify-compat/callouts/Warning.astro +1 -1
- package/stl-docs/components/mintlify-compat/card.css +33 -35
- package/stl-docs/components/nav-tabs/NavDropdown.astro +31 -70
- package/stl-docs/components/nav-tabs/NavTabs.astro +78 -80
- package/stl-docs/components/nav-tabs/SecondaryNavTabs.astro +15 -8
- package/stl-docs/components/nav-tabs/buildNavLinks.ts +3 -2
- package/stl-docs/components/pagination/HomeLink.astro +10 -0
- package/stl-docs/components/pagination/Pagination.astro +175 -0
- package/stl-docs/components/pagination/PaginationLinkEmphasized.astro +22 -0
- package/stl-docs/components/pagination/PaginationLinkQuiet.astro +13 -0
- package/stl-docs/components/pagination/util.ts +71 -0
- package/stl-docs/components/scripts.ts +1 -0
- package/stl-docs/disableCalloutSyntax.ts +36 -0
- package/stl-docs/index.ts +130 -48
- package/stl-docs/loadStlDocsConfig.ts +44 -4
- package/stl-docs/proseMarkdown/proseMarkdownIntegration.ts +64 -0
- package/stl-docs/proseMarkdown/proseMarkdownMiddleware.ts +34 -0
- package/stl-docs/proseMarkdown/toMarkdown.ts +158 -0
- package/stl-docs/proseSearchIndexing.ts +113 -0
- package/stl-docs/tabsMiddleware.ts +11 -3
- package/styles/code.css +108 -140
- package/styles/fonts.css +32 -17
- package/styles/links.css +11 -48
- package/styles/method-descriptions.css +36 -0
- package/styles/overrides.css +48 -60
- package/styles/page.css +92 -52
- package/styles/sdk_select.css +9 -7
- package/styles/search.css +58 -69
- package/styles/sidebar.css +211 -131
- package/styles/{variables.css → sl-variables.css} +3 -2
- package/styles/stldocs-variables.css +6 -0
- package/styles/toc.css +41 -34
- package/theme.css +10 -10
- package/tsconfig.json +2 -5
- package/virtual-module.d.ts +23 -3
- package/components/variables.css +0 -135
- /package/{plugin/assets → assets}/fonts/geist/OFL.txt +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-italic-latin-ext.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-italic-latin.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-latin-ext.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-latin.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-mono-italic-latin-ext.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-mono-italic-latin.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-mono-latin-ext.woff2 +0 -0
- /package/{plugin/assets → assets}/fonts/geist/geist-mono-latin.woff2 +0 -0
package/plugin/react/Routing.tsx
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { marked } from 'marked';
|
|
3
|
-
|
|
4
|
-
import {
|
|
2
|
+
import { marked, Tokens } from 'marked';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
createMarkdownProcessor,
|
|
6
|
+
CreateShikiHighlighterOptions,
|
|
7
|
+
type MarkdownProcessor,
|
|
8
|
+
} from '@astrojs/markdown-remark';
|
|
5
9
|
import remarkGfmAlerts from 'remark-github-alerts';
|
|
6
10
|
|
|
7
11
|
import type { MarkdownHeading } from 'astro';
|
|
8
12
|
import type { StarlightRouteData } from '@astrojs/starlight/route-data';
|
|
9
|
-
import type * as SDKJSON from '
|
|
10
|
-
import type
|
|
13
|
+
import type * as SDKJSON from '@stainless/sdk-json';
|
|
14
|
+
import { LanguageNames, SupportedLanguageSyntaxes, type DocsLanguage } from '@stainless-api/docs-ui/routing';
|
|
11
15
|
|
|
12
16
|
import {
|
|
13
17
|
generateRouteList,
|
|
14
18
|
generateRoute,
|
|
15
19
|
parseStainlessPath,
|
|
16
20
|
walkTree,
|
|
17
|
-
SupportedLanguageSyntaxes,
|
|
18
21
|
getLanguageSnippet,
|
|
19
|
-
} from '@stainless-api/docs-ui/
|
|
22
|
+
} from '@stainless-api/docs-ui/routing';
|
|
20
23
|
|
|
21
24
|
import {
|
|
22
25
|
DocsProvider,
|
|
@@ -24,23 +27,22 @@ import {
|
|
|
24
27
|
NavigationProvider,
|
|
25
28
|
useSpec,
|
|
26
29
|
type ContentPanelLayout,
|
|
27
|
-
} from '@stainless-api/docs-ui/
|
|
30
|
+
} from '@stainless-api/docs-ui/contexts';
|
|
28
31
|
|
|
29
|
-
import { flatResources, getResourceFromSpec } from '@stainless-api/docs-ui/
|
|
32
|
+
import { flatResources, getResourceFromSpec } from '@stainless-api/docs-ui/utils';
|
|
30
33
|
|
|
31
34
|
import {
|
|
32
35
|
SDKMethod,
|
|
33
36
|
SDKResource,
|
|
34
37
|
type SDKRequestTitleProps,
|
|
35
38
|
SDKBreadcrumbs,
|
|
36
|
-
Dropdown,
|
|
37
|
-
DropdownTrigger,
|
|
38
|
-
DropdownMenu,
|
|
39
|
-
DropdownItem,
|
|
40
39
|
SDKIcon,
|
|
41
40
|
SDKOverview,
|
|
42
41
|
SDKLanguageBlock,
|
|
43
|
-
} from '@stainless-api/docs-ui/
|
|
42
|
+
} from '@stainless-api/docs-ui/components';
|
|
43
|
+
|
|
44
|
+
import { Dropdown } from '@stainless-api/docs/components';
|
|
45
|
+
|
|
44
46
|
import {
|
|
45
47
|
BASE_PATH,
|
|
46
48
|
EXCLUDE_LANGUAGES,
|
|
@@ -48,13 +50,22 @@ import {
|
|
|
48
50
|
HIGHLIGHT_THEMES,
|
|
49
51
|
BREADCRUMB_CONFIG,
|
|
50
52
|
PROPERTY_SETTINGS,
|
|
53
|
+
ENABLE_CONTEXT_MENU,
|
|
54
|
+
EXPERIMENTAL_COLLAPSIBLE_METHOD_DESCRIPTIONS,
|
|
51
55
|
} from 'virtual:stl-starlight-virtual-module';
|
|
52
|
-
import style from '@stainless-api/docs-ui/
|
|
53
|
-
import {
|
|
54
|
-
import {
|
|
55
|
-
|
|
56
|
+
import style from '@stainless-api/docs-ui/style';
|
|
57
|
+
import { BundledTheme, createHighlighter, HighlighterGeneric, type BundledLanguage } from 'shiki';
|
|
58
|
+
import {
|
|
59
|
+
SnippetCode,
|
|
60
|
+
SnippetContainer,
|
|
61
|
+
SnippetRequestContainer,
|
|
62
|
+
SnippetButtons,
|
|
63
|
+
} from '../components/SnippetCode';
|
|
56
64
|
import type { StlStarlightMiddleware } from '../middlewareBuilder/stainlessMiddleware';
|
|
57
|
-
import { ComponentProvider } from '@stainless-api/docs-ui/
|
|
65
|
+
import { ComponentProvider } from '@stainless-api/docs-ui/contexts/component';
|
|
66
|
+
import { AIDropdown } from '../../stl-docs/components/AIDropdown';
|
|
67
|
+
import { ChevronsUpDownIcon } from 'lucide-react';
|
|
68
|
+
import { MethodDescription } from '../components/MethodDescription';
|
|
58
69
|
|
|
59
70
|
export function generateDocsRoutes(spec: SDKJSON.Spec) {
|
|
60
71
|
const paths = generateRouteList({
|
|
@@ -119,7 +130,6 @@ export function buildSidebar(
|
|
|
119
130
|
|
|
120
131
|
const meths: SidebarEntry[] = Object.values(resource.methods ?? [])
|
|
121
132
|
.filter((method) => spec.decls?.[language]?.[method.stainlessPath])
|
|
122
|
-
.toSorted((first, second) => first.name.localeCompare(second.name))
|
|
123
133
|
.map((method) => ({
|
|
124
134
|
type: 'link',
|
|
125
135
|
isCurrent: current === method.stainlessPath,
|
|
@@ -151,19 +161,58 @@ export function buildPageNavigation(resource: SDKJSON.Resource, depth: number =
|
|
|
151
161
|
return [...output, ...subs];
|
|
152
162
|
}
|
|
153
163
|
|
|
154
|
-
function renderMarkdown(content: string) {
|
|
155
|
-
|
|
164
|
+
async function renderMarkdown(content: string) {
|
|
165
|
+
const highlighter = await astroHighlight();
|
|
166
|
+
|
|
167
|
+
const renderer = {
|
|
168
|
+
code({ text, lang }: Tokens.Code) {
|
|
169
|
+
return shikiHighlight({
|
|
170
|
+
highlighter,
|
|
171
|
+
content: text,
|
|
172
|
+
language: lang,
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
marked.use({ renderer });
|
|
178
|
+
return marked.parse(content, {
|
|
179
|
+
gfm: true,
|
|
180
|
+
}) as string;
|
|
156
181
|
}
|
|
157
182
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
183
|
+
function shikiHighlight({
|
|
184
|
+
highlighter,
|
|
185
|
+
content,
|
|
186
|
+
language,
|
|
187
|
+
themes,
|
|
188
|
+
}: {
|
|
189
|
+
highlighter: HighlighterGeneric<BundledLanguage, BundledTheme>;
|
|
190
|
+
content: string;
|
|
191
|
+
language?: string;
|
|
192
|
+
themes?: CreateShikiHighlighterOptions['themes'] | Record<string, 'stainless-docs-json'>;
|
|
193
|
+
}) {
|
|
194
|
+
let _themes = themes;
|
|
195
|
+
if (!themes && language === 'json') {
|
|
196
|
+
_themes = {
|
|
197
|
+
light: 'stainless-docs-json',
|
|
198
|
+
dark: 'stainless-docs-json',
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (!_themes) {
|
|
203
|
+
_themes = HIGHLIGHT_THEMES;
|
|
204
|
+
}
|
|
161
205
|
return highlighter.codeToHtml(content, {
|
|
162
206
|
lang: language ?? 'javascript',
|
|
163
|
-
themes:
|
|
207
|
+
themes: _themes || {},
|
|
164
208
|
});
|
|
165
209
|
}
|
|
166
210
|
|
|
211
|
+
async function highlight(content: string, language?: string) {
|
|
212
|
+
const highlighter = await astroHighlight();
|
|
213
|
+
return shikiHighlight({ highlighter, content, language });
|
|
214
|
+
}
|
|
215
|
+
|
|
167
216
|
export function SDKSelectReactComponent({
|
|
168
217
|
selected,
|
|
169
218
|
languages,
|
|
@@ -177,30 +226,36 @@ export function SDKSelectReactComponent({
|
|
|
177
226
|
}) {
|
|
178
227
|
return (
|
|
179
228
|
<Dropdown id={id} data-current-value={selected} className={className}>
|
|
180
|
-
<
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
<
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
229
|
+
<Dropdown.Trigger>
|
|
230
|
+
<Dropdown.TriggerSelectedItem>
|
|
231
|
+
<Dropdown.Icon>
|
|
232
|
+
<SDKIcon language={getLanguageSnippet(selected)} />
|
|
233
|
+
</Dropdown.Icon>
|
|
234
|
+
<span className="stl-snippet-dropdown-button-text">{LanguageNames[selected]}</span>
|
|
235
|
+
</Dropdown.TriggerSelectedItem>
|
|
236
|
+
<Dropdown.TriggerIcon>
|
|
237
|
+
<ChevronsUpDownIcon size={16} />
|
|
238
|
+
</Dropdown.TriggerIcon>
|
|
239
|
+
</Dropdown.Trigger>
|
|
240
|
+
<Dropdown.Menu
|
|
191
241
|
className="dropdown-menu stl-sdk-select-dropdown-menu"
|
|
192
|
-
|
|
193
|
-
aria-labelledby="stldocs-snippet-title-button"
|
|
242
|
+
aria-labelledby="stl-docs-snippet-title-button"
|
|
194
243
|
>
|
|
195
244
|
{languages.map((item) => (
|
|
196
|
-
<
|
|
197
|
-
<
|
|
245
|
+
<Dropdown.MenuItem key={item} value={item} isSelected={item === selected}>
|
|
246
|
+
<Dropdown.Icon>
|
|
198
247
|
<SDKIcon language={getLanguageSnippet(item)} size={16} />
|
|
199
|
-
|
|
200
|
-
</
|
|
201
|
-
|
|
248
|
+
</Dropdown.Icon>
|
|
249
|
+
<Dropdown.MenuItemText>{LanguageNames[item]}</Dropdown.MenuItemText>
|
|
250
|
+
<Dropdown.MenuItemTemplate>
|
|
251
|
+
<Dropdown.Icon>
|
|
252
|
+
<SDKIcon language={getLanguageSnippet(item)} size={16} />
|
|
253
|
+
</Dropdown.Icon>
|
|
254
|
+
<span className="stl-snippet-dropdown-button-text">{LanguageNames[item]}</span>
|
|
255
|
+
</Dropdown.MenuItemTemplate>
|
|
256
|
+
</Dropdown.MenuItem>
|
|
202
257
|
))}
|
|
203
|
-
</
|
|
258
|
+
</Dropdown.Menu>
|
|
204
259
|
</Dropdown>
|
|
205
260
|
);
|
|
206
261
|
}
|
|
@@ -216,13 +271,13 @@ function SDKRequestTitle({ snippetLanguage }: SDKRequestTitleProps) {
|
|
|
216
271
|
selected={selected || 'http'}
|
|
217
272
|
languages={languages}
|
|
218
273
|
id="stldocs-snippet-select"
|
|
219
|
-
className="stl-sdk-select"
|
|
274
|
+
className="stl-sdk-select stl-ui-not-prose"
|
|
220
275
|
/>
|
|
221
276
|
);
|
|
222
277
|
}
|
|
223
278
|
|
|
224
279
|
export type SpecMetadata = [
|
|
225
|
-
|
|
280
|
+
DocsLanguage,
|
|
226
281
|
{
|
|
227
282
|
repo_url?: string;
|
|
228
283
|
code_url?: string;
|
|
@@ -232,9 +287,18 @@ export type SpecMetadata = [
|
|
|
232
287
|
},
|
|
233
288
|
][];
|
|
234
289
|
|
|
290
|
+
const componentOverrides = {
|
|
291
|
+
SDKRequestTitle,
|
|
292
|
+
SnippetCode,
|
|
293
|
+
SnippetContainer,
|
|
294
|
+
SnippetRequestContainer,
|
|
295
|
+
SnippetButtons,
|
|
296
|
+
...(EXPERIMENTAL_COLLAPSIBLE_METHOD_DESCRIPTIONS ? { MethodDescription } : {}),
|
|
297
|
+
};
|
|
298
|
+
|
|
235
299
|
export function RenderLibraries({ metadata }: { metadata: SpecMetadata }) {
|
|
236
300
|
return (
|
|
237
|
-
<ComponentProvider components={
|
|
301
|
+
<ComponentProvider components={componentOverrides}>
|
|
238
302
|
{metadata.map(([language, data]) => (
|
|
239
303
|
<SDKLanguageBlock
|
|
240
304
|
language={language}
|
|
@@ -252,14 +316,7 @@ export function RenderSpecOverview({ spec, language }: { spec: SDKJSON.Spec; lan
|
|
|
252
316
|
|
|
253
317
|
return (
|
|
254
318
|
<DocsProvider spec={spec} language={language ?? 'node'}>
|
|
255
|
-
<ComponentProvider
|
|
256
|
-
components={{
|
|
257
|
-
SDKRequestTitle,
|
|
258
|
-
SnippetCode,
|
|
259
|
-
SnippetContainer,
|
|
260
|
-
SnippetRequestContainer,
|
|
261
|
-
}}
|
|
262
|
-
>
|
|
319
|
+
<ComponentProvider components={componentOverrides}>
|
|
263
320
|
<NavigationProvider basePath={BASE_PATH}>
|
|
264
321
|
<MarkdownProvider render={renderMarkdown} highlight={highlight}>
|
|
265
322
|
<div className={style.Overview}>
|
|
@@ -301,7 +358,10 @@ export function RenderSpec({
|
|
|
301
358
|
const parsed = parseStainlessPath(path);
|
|
302
359
|
const resource = getResourceFromSpec(path, spec);
|
|
303
360
|
|
|
304
|
-
if (!resource || !parsed)
|
|
361
|
+
if (!resource || !parsed) {
|
|
362
|
+
console.warn(`Could not find resource or parsed path for '${path}'`);
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
305
365
|
|
|
306
366
|
return (
|
|
307
367
|
<DocsProvider
|
|
@@ -312,40 +372,30 @@ export function RenderSpec({
|
|
|
312
372
|
properties: PROPERTY_SETTINGS,
|
|
313
373
|
}}
|
|
314
374
|
>
|
|
315
|
-
<ComponentProvider
|
|
316
|
-
components={{
|
|
317
|
-
SDKRequestTitle,
|
|
318
|
-
SnippetCode,
|
|
319
|
-
SnippetContainer,
|
|
320
|
-
SnippetRequestContainer,
|
|
321
|
-
}}
|
|
322
|
-
>
|
|
375
|
+
<ComponentProvider components={componentOverrides}>
|
|
323
376
|
<NavigationProvider basePath={BASE_PATH} selectedPath={path}>
|
|
324
377
|
<MarkdownProvider render={renderMarkdown} highlight={highlight}>
|
|
325
|
-
{
|
|
326
|
-
<div className="stldocs-root stl-ui-not-prose">
|
|
327
|
-
<SDKBreadcrumbs
|
|
328
|
-
spec={spec as SDKJSON.Spec}
|
|
329
|
-
currentPath={currentPath}
|
|
330
|
-
basePath={BASE_PATH}
|
|
331
|
-
config={BREADCRUMB_CONFIG}
|
|
332
|
-
/>
|
|
333
|
-
<SDKMethod
|
|
334
|
-
method={resource.methods[parsed.method]}
|
|
335
|
-
transformRequestSnippet={transformRequestSnippet}
|
|
336
|
-
/>
|
|
337
|
-
</div>
|
|
338
|
-
) : (
|
|
378
|
+
{
|
|
339
379
|
<div className="stldocs-root stl-ui-not-prose">
|
|
340
|
-
<
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
380
|
+
<div className="stl-page-nav-container">
|
|
381
|
+
<SDKBreadcrumbs
|
|
382
|
+
spec={spec as SDKJSON.Spec}
|
|
383
|
+
currentPath={currentPath}
|
|
384
|
+
basePath={BASE_PATH}
|
|
385
|
+
config={BREADCRUMB_CONFIG}
|
|
386
|
+
/>
|
|
387
|
+
{ENABLE_CONTEXT_MENU && <AIDropdown />}
|
|
388
|
+
</div>
|
|
389
|
+
{kind === 'http_method' ? (
|
|
390
|
+
<SDKMethod
|
|
391
|
+
method={resource.methods[parsed.method!]!}
|
|
392
|
+
transformRequestSnippet={transformRequestSnippet}
|
|
393
|
+
/>
|
|
394
|
+
) : (
|
|
395
|
+
<SDKOverview resource={resource} />
|
|
396
|
+
)}
|
|
347
397
|
</div>
|
|
348
|
-
|
|
398
|
+
}
|
|
349
399
|
</MarkdownProvider>
|
|
350
400
|
</NavigationProvider>
|
|
351
401
|
</ComponentProvider>
|
|
@@ -359,10 +409,14 @@ export function RenderMethod({ path }: { path: string }) {
|
|
|
359
409
|
|
|
360
410
|
const parsed = parseStainlessPath(path);
|
|
361
411
|
const resource = getResourceFromSpec(path, spec);
|
|
362
|
-
if (!resource || !parsed) return null;
|
|
363
412
|
|
|
364
|
-
|
|
365
|
-
|
|
413
|
+
if (!resource || !parsed) {
|
|
414
|
+
console.warn(`Could not find resource or parsed path for '${path}'`);
|
|
415
|
+
return null;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const method = resource.methods[parsed.method!]!;
|
|
419
|
+
return <SDKMethod method={method} />;
|
|
366
420
|
}
|
|
367
421
|
|
|
368
422
|
export async function getReadmeContent(spec: SDKJSON.Spec, language: DocsLanguage) {
|
|
@@ -375,13 +429,75 @@ export async function getReadmeContent(spec: SDKJSON.Spec, language: DocsLanguag
|
|
|
375
429
|
const response = await fetch(`${rawUrl}/refs/heads/main/README.md`);
|
|
376
430
|
if (response && response.ok) return response.text();
|
|
377
431
|
}
|
|
378
|
-
} catch
|
|
432
|
+
} catch {
|
|
433
|
+
// ignore
|
|
434
|
+
}
|
|
379
435
|
|
|
380
436
|
return spec.readme[language];
|
|
381
437
|
}
|
|
382
438
|
|
|
439
|
+
let astroShikiHighlighter:
|
|
440
|
+
| HighlighterGeneric<BundledLanguage, BundledTheme>
|
|
441
|
+
| Promise<HighlighterGeneric<BundledLanguage, BundledTheme>>
|
|
442
|
+
| null = null;
|
|
443
|
+
|
|
444
|
+
async function astroHighlight() {
|
|
445
|
+
if (astroShikiHighlighter) {
|
|
446
|
+
return astroShikiHighlighter;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
astroShikiHighlighter = createHighlighter({
|
|
450
|
+
themes: [
|
|
451
|
+
'github-light',
|
|
452
|
+
'github-dark',
|
|
453
|
+
{
|
|
454
|
+
name: 'stainless-docs-json',
|
|
455
|
+
colors: {
|
|
456
|
+
'editor.background': 'var(--stl-color-background)',
|
|
457
|
+
'editor.foreground': 'var(--stl-color-foreground)',
|
|
458
|
+
},
|
|
459
|
+
|
|
460
|
+
tokenColors: [
|
|
461
|
+
{
|
|
462
|
+
scope: ['comment', 'punctuation.definition.comment'],
|
|
463
|
+
settings: { foreground: 'var(--stl-color-foreground-muted)' },
|
|
464
|
+
},
|
|
465
|
+
// numbers, booleans, null
|
|
466
|
+
{
|
|
467
|
+
scope: ['constant.numeric', 'constant.language'],
|
|
468
|
+
settings: { foreground: 'var(--stl-color-orange-foreground)' },
|
|
469
|
+
},
|
|
470
|
+
// strings
|
|
471
|
+
{
|
|
472
|
+
scope: ['string', 'string.quoted', 'string.template'],
|
|
473
|
+
settings: { foreground: 'var(--stl-color-green-foreground)' },
|
|
474
|
+
},
|
|
475
|
+
// Keys, brackets
|
|
476
|
+
{
|
|
477
|
+
scope: ['support.type', 'meta'],
|
|
478
|
+
settings: { foreground: 'var(--stl-color-foreground)' },
|
|
479
|
+
},
|
|
480
|
+
// brackets
|
|
481
|
+
{
|
|
482
|
+
scope: ['meta'],
|
|
483
|
+
settings: { foreground: 'var(--stl-color-foreground-muted)' },
|
|
484
|
+
},
|
|
485
|
+
// built-in types
|
|
486
|
+
{
|
|
487
|
+
scope: ['support.type.builtin'],
|
|
488
|
+
settings: { foreground: 'var(--stl-color-purple-foreground)' },
|
|
489
|
+
},
|
|
490
|
+
],
|
|
491
|
+
},
|
|
492
|
+
],
|
|
493
|
+
langs: SupportedLanguageSyntaxes,
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
return astroShikiHighlighter;
|
|
497
|
+
}
|
|
498
|
+
|
|
383
499
|
// Astro's markdown processor is a singleton
|
|
384
|
-
// Need to cache it instead of
|
|
500
|
+
// Need to cache it instead of instantiating per request
|
|
385
501
|
let astroMarkdownProcessor: MarkdownProcessor;
|
|
386
502
|
async function astroMarkdown() {
|
|
387
503
|
if (!astroMarkdownProcessor) {
|
|
@@ -397,18 +513,6 @@ async function astroMarkdown() {
|
|
|
397
513
|
return astroMarkdownProcessor;
|
|
398
514
|
}
|
|
399
515
|
|
|
400
|
-
let astroShikiHighlighter: HighlighterGeneric<BundledLanguage, BundledTheme>;
|
|
401
|
-
async function astroHighlight() {
|
|
402
|
-
if (!astroShikiHighlighter) {
|
|
403
|
-
astroShikiHighlighter = await createHighlighter({
|
|
404
|
-
themes: ['github-light', 'github-dark'],
|
|
405
|
-
langs: SupportedLanguageSyntaxes,
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
return astroShikiHighlighter;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
516
|
export async function astroMarkdownRender(content: string) {
|
|
413
517
|
const md = await astroMarkdown();
|
|
414
518
|
const output = await md.render(content);
|
|
@@ -58,7 +58,7 @@ function recursiveGetPlaceholderItems(
|
|
|
58
58
|
items: PlaceholderItemResult[],
|
|
59
59
|
): PlaceholderItemResult[] {
|
|
60
60
|
for (let i = 0; i < sidebar.length; i++) {
|
|
61
|
-
const entry = sidebar[i]
|
|
61
|
+
const entry = sidebar[i]!;
|
|
62
62
|
if ('attrs' in entry && entry.attrs?.about === INTERNAL_REFERENCE_ENTRY_MARKER) {
|
|
63
63
|
items.push({
|
|
64
64
|
index: i,
|
|
@@ -5,7 +5,7 @@ import { BASE_PATH } from 'virtual:stl-starlight-virtual-module';
|
|
|
5
5
|
import { getAPIReferencePlaceholderItems } from './referencePlaceholderUtils';
|
|
6
6
|
import { getMethodFromSDKJSON, recursiveReplacePlaceholderItems } from './generateAPIReferenceLink';
|
|
7
7
|
import { forceGenerateRoute } from './cms/sidebar-builder';
|
|
8
|
-
import { parseRoute } from '@stainless-api/docs-ui/
|
|
8
|
+
import { parseRoute } from '@stainless-api/docs-ui/routing';
|
|
9
9
|
|
|
10
10
|
// this fn is loaded in the plugin via addRouteMiddleware
|
|
11
11
|
|
|
@@ -15,6 +15,10 @@ export const onRequest = defineRouteMiddleware(async (context) => {
|
|
|
15
15
|
|
|
16
16
|
const slug = `/${context.locals.starlightRoute.id}`; // same as .slug but not deprecated
|
|
17
17
|
|
|
18
|
+
context.locals.starlightRoute._stlStarlight = {
|
|
19
|
+
basePath: BASE_PATH,
|
|
20
|
+
};
|
|
21
|
+
|
|
18
22
|
const apiReferencePlaceholderItems = getAPIReferencePlaceholderItems(context.locals.starlightRoute.sidebar);
|
|
19
23
|
|
|
20
24
|
const spec = await cmsClient.getSpec();
|