@stainless-api/docs 0.1.0-beta.7 → 0.1.0-beta.70
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 +554 -0
- package/README.md +1 -1
- package/eslint-suppressions.json +52 -0
- package/locals.d.ts +17 -0
- package/package.json +51 -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 +45 -28
- 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 +243 -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/helpers/generateDocsRoutes.ts +27 -0
- package/plugin/index.ts +178 -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 -129
- package/plugin/referencePlaceholderUtils.ts +1 -1
- package/plugin/replaceSidebarPlaceholderMiddleware.ts +5 -1
- package/plugin/routes/Docs.astro +62 -89
- package/plugin/routes/DocsStatic.astro +1 -1
- package/plugin/routes/Overview.astro +10 -16
- package/plugin/routes/markdown.ts +9 -8
- 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/getProsePages.ts +42 -0
- 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 +14 -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 +18 -0
- package/stl-docs/components/PageTitle.astro +82 -0
- package/stl-docs/components/TableOfContents.astro +34 -0
- package/stl-docs/components/ThemeProvider.astro +36 -0
- package/stl-docs/components/ThemeSelect.astro +84 -139
- 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/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/mintlify-compat/index.ts +2 -4
- 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 +141 -50
- package/stl-docs/loadStlDocsConfig.ts +45 -5
- package/stl-docs/proseMarkdown/proseMarkdownIntegration.ts +61 -0
- package/stl-docs/proseMarkdown/proseMarkdownMiddleware.ts +39 -0
- package/stl-docs/proseMarkdown/toMarkdown.ts +158 -0
- package/stl-docs/proseSearchIndexing.ts +450 -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 +56 -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 +26 -4
- package/components/variables.css +0 -135
- package/stl-docs/components/mintlify-compat/Step.astro +0 -58
- package/stl-docs/components/mintlify-compat/Steps.astro +0 -17
- /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,24 @@
|
|
|
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
|
-
generateRouteList,
|
|
14
17
|
generateRoute,
|
|
15
18
|
parseStainlessPath,
|
|
16
19
|
walkTree,
|
|
17
|
-
SupportedLanguageSyntaxes,
|
|
18
20
|
getLanguageSnippet,
|
|
19
|
-
} from '@stainless-api/docs-ui/
|
|
21
|
+
} from '@stainless-api/docs-ui/routing';
|
|
20
22
|
|
|
21
23
|
import {
|
|
22
24
|
DocsProvider,
|
|
@@ -24,23 +26,22 @@ import {
|
|
|
24
26
|
NavigationProvider,
|
|
25
27
|
useSpec,
|
|
26
28
|
type ContentPanelLayout,
|
|
27
|
-
} from '@stainless-api/docs-ui/
|
|
29
|
+
} from '@stainless-api/docs-ui/contexts';
|
|
28
30
|
|
|
29
|
-
import { flatResources, getResourceFromSpec } from '@stainless-api/docs-ui/
|
|
31
|
+
import { flatResources, getResourceFromSpec } from '@stainless-api/docs-ui/utils';
|
|
30
32
|
|
|
31
33
|
import {
|
|
32
34
|
SDKMethod,
|
|
33
35
|
SDKResource,
|
|
34
36
|
type SDKRequestTitleProps,
|
|
35
37
|
SDKBreadcrumbs,
|
|
36
|
-
Dropdown,
|
|
37
|
-
DropdownTrigger,
|
|
38
|
-
DropdownMenu,
|
|
39
|
-
DropdownItem,
|
|
40
38
|
SDKIcon,
|
|
41
39
|
SDKOverview,
|
|
42
40
|
SDKLanguageBlock,
|
|
43
|
-
} from '@stainless-api/docs-ui/
|
|
41
|
+
} from '@stainless-api/docs-ui/components';
|
|
42
|
+
|
|
43
|
+
import { Dropdown } from '@stainless-api/docs/components';
|
|
44
|
+
|
|
44
45
|
import {
|
|
45
46
|
BASE_PATH,
|
|
46
47
|
EXCLUDE_LANGUAGES,
|
|
@@ -48,37 +49,22 @@ import {
|
|
|
48
49
|
HIGHLIGHT_THEMES,
|
|
49
50
|
BREADCRUMB_CONFIG,
|
|
50
51
|
PROPERTY_SETTINGS,
|
|
52
|
+
ENABLE_CONTEXT_MENU,
|
|
53
|
+
EXPERIMENTAL_COLLAPSIBLE_METHOD_DESCRIPTIONS,
|
|
51
54
|
} from 'virtual:stl-starlight-virtual-module';
|
|
52
|
-
import style from '@stainless-api/docs-ui/
|
|
53
|
-
import {
|
|
54
|
-
import {
|
|
55
|
-
|
|
55
|
+
import style from '@stainless-api/docs-ui/style';
|
|
56
|
+
import { BundledTheme, createHighlighter, HighlighterGeneric, type BundledLanguage } from 'shiki';
|
|
57
|
+
import {
|
|
58
|
+
SnippetCode,
|
|
59
|
+
SnippetContainer,
|
|
60
|
+
SnippetRequestContainer,
|
|
61
|
+
SnippetButtons,
|
|
62
|
+
} from '../components/SnippetCode';
|
|
56
63
|
import type { StlStarlightMiddleware } from '../middlewareBuilder/stainlessMiddleware';
|
|
57
|
-
import { ComponentProvider } from '@stainless-api/docs-ui/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
spec,
|
|
62
|
-
excludeLanguages: EXCLUDE_LANGUAGES as DocsLanguage[],
|
|
63
|
-
});
|
|
64
|
-
const readmes = Object.entries(spec.readme)
|
|
65
|
-
.filter(([language]) => language !== 'http')
|
|
66
|
-
.filter(([language]) => !EXCLUDE_LANGUAGES.includes(language as DocsLanguage))
|
|
67
|
-
.map(([language]) => ({
|
|
68
|
-
slug: language,
|
|
69
|
-
stainlessPath: null,
|
|
70
|
-
language: language as DocsLanguage,
|
|
71
|
-
title: 'Readme',
|
|
72
|
-
kind: 'readme',
|
|
73
|
-
}));
|
|
74
|
-
|
|
75
|
-
return [...paths, ...readmes].map(({ slug, stainlessPath, language, title, kind }) => {
|
|
76
|
-
return {
|
|
77
|
-
params: { slug },
|
|
78
|
-
props: { stainlessPath, language, title, kind },
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
}
|
|
64
|
+
import { ComponentProvider } from '@stainless-api/docs-ui/contexts/component';
|
|
65
|
+
import { AIDropdown } from '../../stl-docs/components/AIDropdown';
|
|
66
|
+
import { ChevronsUpDownIcon } from 'lucide-react';
|
|
67
|
+
import { MethodDescription } from '../components/MethodDescription';
|
|
82
68
|
|
|
83
69
|
function isResourceNonEmpty(resource: SDKJSON.Resource) {
|
|
84
70
|
return (
|
|
@@ -119,7 +105,6 @@ export function buildSidebar(
|
|
|
119
105
|
|
|
120
106
|
const meths: SidebarEntry[] = Object.values(resource.methods ?? [])
|
|
121
107
|
.filter((method) => spec.decls?.[language]?.[method.stainlessPath])
|
|
122
|
-
.toSorted((first, second) => first.name.localeCompare(second.name))
|
|
123
108
|
.map((method) => ({
|
|
124
109
|
type: 'link',
|
|
125
110
|
isCurrent: current === method.stainlessPath,
|
|
@@ -151,19 +136,58 @@ export function buildPageNavigation(resource: SDKJSON.Resource, depth: number =
|
|
|
151
136
|
return [...output, ...subs];
|
|
152
137
|
}
|
|
153
138
|
|
|
154
|
-
function renderMarkdown(content: string) {
|
|
155
|
-
|
|
139
|
+
async function renderMarkdown(content: string) {
|
|
140
|
+
const highlighter = await astroHighlight();
|
|
141
|
+
|
|
142
|
+
const renderer = {
|
|
143
|
+
code({ text, lang }: Tokens.Code) {
|
|
144
|
+
return shikiHighlight({
|
|
145
|
+
highlighter,
|
|
146
|
+
content: text,
|
|
147
|
+
language: lang,
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
marked.use({ renderer });
|
|
153
|
+
return marked.parse(content, {
|
|
154
|
+
gfm: true,
|
|
155
|
+
}) as string;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
function shikiHighlight({
|
|
159
|
+
highlighter,
|
|
160
|
+
content,
|
|
161
|
+
language,
|
|
162
|
+
themes,
|
|
163
|
+
}: {
|
|
164
|
+
highlighter: HighlighterGeneric<BundledLanguage, BundledTheme>;
|
|
165
|
+
content: string;
|
|
166
|
+
language?: string;
|
|
167
|
+
themes?: CreateShikiHighlighterOptions['themes'] | Record<string, 'stainless-docs-json'>;
|
|
168
|
+
}) {
|
|
169
|
+
let _themes = themes;
|
|
170
|
+
if (!themes && language === 'json') {
|
|
171
|
+
_themes = {
|
|
172
|
+
light: 'stainless-docs-json',
|
|
173
|
+
dark: 'stainless-docs-json',
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (!_themes) {
|
|
178
|
+
_themes = HIGHLIGHT_THEMES;
|
|
179
|
+
}
|
|
161
180
|
return highlighter.codeToHtml(content, {
|
|
162
181
|
lang: language ?? 'javascript',
|
|
163
|
-
themes:
|
|
182
|
+
themes: _themes || {},
|
|
164
183
|
});
|
|
165
184
|
}
|
|
166
185
|
|
|
186
|
+
async function highlight(content: string, language?: string) {
|
|
187
|
+
const highlighter = await astroHighlight();
|
|
188
|
+
return shikiHighlight({ highlighter, content, language });
|
|
189
|
+
}
|
|
190
|
+
|
|
167
191
|
export function SDKSelectReactComponent({
|
|
168
192
|
selected,
|
|
169
193
|
languages,
|
|
@@ -177,30 +201,36 @@ export function SDKSelectReactComponent({
|
|
|
177
201
|
}) {
|
|
178
202
|
return (
|
|
179
203
|
<Dropdown id={id} data-current-value={selected} className={className}>
|
|
180
|
-
<
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
<
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
204
|
+
<Dropdown.Trigger>
|
|
205
|
+
<Dropdown.TriggerSelectedItem>
|
|
206
|
+
<Dropdown.Icon>
|
|
207
|
+
<SDKIcon language={getLanguageSnippet(selected)} />
|
|
208
|
+
</Dropdown.Icon>
|
|
209
|
+
<span className="stl-snippet-dropdown-button-text">{LanguageNames[selected]}</span>
|
|
210
|
+
</Dropdown.TriggerSelectedItem>
|
|
211
|
+
<Dropdown.TriggerIcon>
|
|
212
|
+
<ChevronsUpDownIcon size={16} />
|
|
213
|
+
</Dropdown.TriggerIcon>
|
|
214
|
+
</Dropdown.Trigger>
|
|
215
|
+
<Dropdown.Menu
|
|
191
216
|
className="dropdown-menu stl-sdk-select-dropdown-menu"
|
|
192
|
-
|
|
193
|
-
aria-labelledby="stldocs-snippet-title-button"
|
|
217
|
+
aria-labelledby="stl-docs-snippet-title-button"
|
|
194
218
|
>
|
|
195
219
|
{languages.map((item) => (
|
|
196
|
-
<
|
|
197
|
-
<
|
|
220
|
+
<Dropdown.MenuItem key={item} value={item} isSelected={item === selected}>
|
|
221
|
+
<Dropdown.Icon>
|
|
198
222
|
<SDKIcon language={getLanguageSnippet(item)} size={16} />
|
|
199
|
-
|
|
200
|
-
</
|
|
201
|
-
|
|
223
|
+
</Dropdown.Icon>
|
|
224
|
+
<Dropdown.MenuItemText>{LanguageNames[item]}</Dropdown.MenuItemText>
|
|
225
|
+
<Dropdown.MenuItemTemplate>
|
|
226
|
+
<Dropdown.Icon>
|
|
227
|
+
<SDKIcon language={getLanguageSnippet(item)} size={16} />
|
|
228
|
+
</Dropdown.Icon>
|
|
229
|
+
<span className="stl-snippet-dropdown-button-text">{LanguageNames[item]}</span>
|
|
230
|
+
</Dropdown.MenuItemTemplate>
|
|
231
|
+
</Dropdown.MenuItem>
|
|
202
232
|
))}
|
|
203
|
-
</
|
|
233
|
+
</Dropdown.Menu>
|
|
204
234
|
</Dropdown>
|
|
205
235
|
);
|
|
206
236
|
}
|
|
@@ -216,13 +246,13 @@ function SDKRequestTitle({ snippetLanguage }: SDKRequestTitleProps) {
|
|
|
216
246
|
selected={selected || 'http'}
|
|
217
247
|
languages={languages}
|
|
218
248
|
id="stldocs-snippet-select"
|
|
219
|
-
className="stl-sdk-select"
|
|
249
|
+
className="stl-sdk-select stl-ui-not-prose"
|
|
220
250
|
/>
|
|
221
251
|
);
|
|
222
252
|
}
|
|
223
253
|
|
|
224
254
|
export type SpecMetadata = [
|
|
225
|
-
|
|
255
|
+
DocsLanguage,
|
|
226
256
|
{
|
|
227
257
|
repo_url?: string;
|
|
228
258
|
code_url?: string;
|
|
@@ -232,9 +262,18 @@ export type SpecMetadata = [
|
|
|
232
262
|
},
|
|
233
263
|
][];
|
|
234
264
|
|
|
265
|
+
const componentOverrides = {
|
|
266
|
+
SDKRequestTitle,
|
|
267
|
+
SnippetCode,
|
|
268
|
+
SnippetContainer,
|
|
269
|
+
SnippetRequestContainer,
|
|
270
|
+
SnippetButtons,
|
|
271
|
+
...(EXPERIMENTAL_COLLAPSIBLE_METHOD_DESCRIPTIONS ? { MethodDescription } : {}),
|
|
272
|
+
};
|
|
273
|
+
|
|
235
274
|
export function RenderLibraries({ metadata }: { metadata: SpecMetadata }) {
|
|
236
275
|
return (
|
|
237
|
-
<ComponentProvider components={
|
|
276
|
+
<ComponentProvider components={componentOverrides}>
|
|
238
277
|
{metadata.map(([language, data]) => (
|
|
239
278
|
<SDKLanguageBlock
|
|
240
279
|
language={language}
|
|
@@ -252,14 +291,7 @@ export function RenderSpecOverview({ spec, language }: { spec: SDKJSON.Spec; lan
|
|
|
252
291
|
|
|
253
292
|
return (
|
|
254
293
|
<DocsProvider spec={spec} language={language ?? 'node'}>
|
|
255
|
-
<ComponentProvider
|
|
256
|
-
components={{
|
|
257
|
-
SDKRequestTitle,
|
|
258
|
-
SnippetCode,
|
|
259
|
-
SnippetContainer,
|
|
260
|
-
SnippetRequestContainer,
|
|
261
|
-
}}
|
|
262
|
-
>
|
|
294
|
+
<ComponentProvider components={componentOverrides}>
|
|
263
295
|
<NavigationProvider basePath={BASE_PATH}>
|
|
264
296
|
<MarkdownProvider render={renderMarkdown} highlight={highlight}>
|
|
265
297
|
<div className={style.Overview}>
|
|
@@ -301,7 +333,10 @@ export function RenderSpec({
|
|
|
301
333
|
const parsed = parseStainlessPath(path);
|
|
302
334
|
const resource = getResourceFromSpec(path, spec);
|
|
303
335
|
|
|
304
|
-
if (!resource || !parsed)
|
|
336
|
+
if (!resource || !parsed) {
|
|
337
|
+
console.warn(`Could not find resource or parsed path for '${path}'`);
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
305
340
|
|
|
306
341
|
return (
|
|
307
342
|
<DocsProvider
|
|
@@ -312,40 +347,30 @@ export function RenderSpec({
|
|
|
312
347
|
properties: PROPERTY_SETTINGS,
|
|
313
348
|
}}
|
|
314
349
|
>
|
|
315
|
-
<ComponentProvider
|
|
316
|
-
components={{
|
|
317
|
-
SDKRequestTitle,
|
|
318
|
-
SnippetCode,
|
|
319
|
-
SnippetContainer,
|
|
320
|
-
SnippetRequestContainer,
|
|
321
|
-
}}
|
|
322
|
-
>
|
|
350
|
+
<ComponentProvider components={componentOverrides}>
|
|
323
351
|
<NavigationProvider basePath={BASE_PATH} selectedPath={path}>
|
|
324
352
|
<MarkdownProvider render={renderMarkdown} highlight={highlight}>
|
|
325
|
-
{
|
|
353
|
+
{
|
|
326
354
|
<div className="stldocs-root stl-ui-not-prose">
|
|
327
|
-
<
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
config={BREADCRUMB_CONFIG}
|
|
345
|
-
/>
|
|
346
|
-
<SDKOverview resource={resource} />
|
|
355
|
+
<div className="stl-page-nav-container">
|
|
356
|
+
<SDKBreadcrumbs
|
|
357
|
+
spec={spec as SDKJSON.Spec}
|
|
358
|
+
currentPath={currentPath}
|
|
359
|
+
basePath={BASE_PATH}
|
|
360
|
+
config={BREADCRUMB_CONFIG}
|
|
361
|
+
/>
|
|
362
|
+
{ENABLE_CONTEXT_MENU && <AIDropdown />}
|
|
363
|
+
</div>
|
|
364
|
+
{kind === 'http_method' ? (
|
|
365
|
+
<SDKMethod
|
|
366
|
+
method={resource.methods[parsed.method!]!}
|
|
367
|
+
transformRequestSnippet={transformRequestSnippet}
|
|
368
|
+
/>
|
|
369
|
+
) : (
|
|
370
|
+
<SDKOverview resource={resource} />
|
|
371
|
+
)}
|
|
347
372
|
</div>
|
|
348
|
-
|
|
373
|
+
}
|
|
349
374
|
</MarkdownProvider>
|
|
350
375
|
</NavigationProvider>
|
|
351
376
|
</ComponentProvider>
|
|
@@ -359,10 +384,14 @@ export function RenderMethod({ path }: { path: string }) {
|
|
|
359
384
|
|
|
360
385
|
const parsed = parseStainlessPath(path);
|
|
361
386
|
const resource = getResourceFromSpec(path, spec);
|
|
362
|
-
if (!resource || !parsed) return null;
|
|
363
387
|
|
|
364
|
-
|
|
365
|
-
|
|
388
|
+
if (!resource || !parsed) {
|
|
389
|
+
console.warn(`Could not find resource or parsed path for '${path}'`);
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const method = resource.methods[parsed.method!]!;
|
|
394
|
+
return <SDKMethod method={method} />;
|
|
366
395
|
}
|
|
367
396
|
|
|
368
397
|
export async function getReadmeContent(spec: SDKJSON.Spec, language: DocsLanguage) {
|
|
@@ -375,13 +404,75 @@ export async function getReadmeContent(spec: SDKJSON.Spec, language: DocsLanguag
|
|
|
375
404
|
const response = await fetch(`${rawUrl}/refs/heads/main/README.md`);
|
|
376
405
|
if (response && response.ok) return response.text();
|
|
377
406
|
}
|
|
378
|
-
} catch
|
|
407
|
+
} catch {
|
|
408
|
+
// ignore
|
|
409
|
+
}
|
|
379
410
|
|
|
380
411
|
return spec.readme[language];
|
|
381
412
|
}
|
|
382
413
|
|
|
414
|
+
let astroShikiHighlighter:
|
|
415
|
+
| HighlighterGeneric<BundledLanguage, BundledTheme>
|
|
416
|
+
| Promise<HighlighterGeneric<BundledLanguage, BundledTheme>>
|
|
417
|
+
| null = null;
|
|
418
|
+
|
|
419
|
+
async function astroHighlight() {
|
|
420
|
+
if (astroShikiHighlighter) {
|
|
421
|
+
return astroShikiHighlighter;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
astroShikiHighlighter = createHighlighter({
|
|
425
|
+
themes: [
|
|
426
|
+
'github-light',
|
|
427
|
+
'github-dark',
|
|
428
|
+
{
|
|
429
|
+
name: 'stainless-docs-json',
|
|
430
|
+
colors: {
|
|
431
|
+
'editor.background': 'var(--stl-color-background)',
|
|
432
|
+
'editor.foreground': 'var(--stl-color-foreground)',
|
|
433
|
+
},
|
|
434
|
+
|
|
435
|
+
tokenColors: [
|
|
436
|
+
{
|
|
437
|
+
scope: ['comment', 'punctuation.definition.comment'],
|
|
438
|
+
settings: { foreground: 'var(--stl-color-foreground-muted)' },
|
|
439
|
+
},
|
|
440
|
+
// numbers, booleans, null
|
|
441
|
+
{
|
|
442
|
+
scope: ['constant.numeric', 'constant.language'],
|
|
443
|
+
settings: { foreground: 'var(--stl-color-orange-foreground)' },
|
|
444
|
+
},
|
|
445
|
+
// strings
|
|
446
|
+
{
|
|
447
|
+
scope: ['string', 'string.quoted', 'string.template'],
|
|
448
|
+
settings: { foreground: 'var(--stl-color-green-foreground)' },
|
|
449
|
+
},
|
|
450
|
+
// Keys, brackets
|
|
451
|
+
{
|
|
452
|
+
scope: ['support.type', 'meta'],
|
|
453
|
+
settings: { foreground: 'var(--stl-color-foreground)' },
|
|
454
|
+
},
|
|
455
|
+
// brackets
|
|
456
|
+
{
|
|
457
|
+
scope: ['meta'],
|
|
458
|
+
settings: { foreground: 'var(--stl-color-foreground-muted)' },
|
|
459
|
+
},
|
|
460
|
+
// built-in types
|
|
461
|
+
{
|
|
462
|
+
scope: ['support.type.builtin'],
|
|
463
|
+
settings: { foreground: 'var(--stl-color-purple-foreground)' },
|
|
464
|
+
},
|
|
465
|
+
],
|
|
466
|
+
},
|
|
467
|
+
],
|
|
468
|
+
langs: SupportedLanguageSyntaxes,
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
return astroShikiHighlighter;
|
|
472
|
+
}
|
|
473
|
+
|
|
383
474
|
// Astro's markdown processor is a singleton
|
|
384
|
-
// Need to cache it instead of
|
|
475
|
+
// Need to cache it instead of instantiating per request
|
|
385
476
|
let astroMarkdownProcessor: MarkdownProcessor;
|
|
386
477
|
async function astroMarkdown() {
|
|
387
478
|
if (!astroMarkdownProcessor) {
|
|
@@ -397,18 +488,6 @@ async function astroMarkdown() {
|
|
|
397
488
|
return astroMarkdownProcessor;
|
|
398
489
|
}
|
|
399
490
|
|
|
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
491
|
export async function astroMarkdownRender(content: string) {
|
|
413
492
|
const md = await astroMarkdown();
|
|
414
493
|
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();
|