@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
|
@@ -34,13 +34,7 @@ const navLinks = buildNavLinks(Astro.locals.starlightRoute);
|
|
|
34
34
|
align-items: center;
|
|
35
35
|
padding: 0;
|
|
36
36
|
list-style: none;
|
|
37
|
-
overflow-x: auto;
|
|
38
37
|
margin-bottom: -1px;
|
|
39
|
-
gap: 0.29rem;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.stl-active-secondary-link:hover {
|
|
43
|
-
background-color: transparent;
|
|
44
38
|
}
|
|
45
39
|
|
|
46
40
|
li {
|
|
@@ -48,7 +42,21 @@ const navLinks = buildNavLinks(Astro.locals.starlightRoute);
|
|
|
48
42
|
border-bottom: 2px solid transparent;
|
|
49
43
|
|
|
50
44
|
&.active {
|
|
51
|
-
border-color: var(--
|
|
45
|
+
border-color: var(--stl-color-accent-border-strong);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.stl-ui-button {
|
|
49
|
+
/* match sidebar. TODO: hoist sidebar variables to use those instead of hardcoding? */
|
|
50
|
+
border-width: 0;
|
|
51
|
+
padding: 8px 12px;
|
|
52
|
+
margin-inline: -12px;
|
|
53
|
+
}
|
|
54
|
+
/* cover for button’s negative margin */
|
|
55
|
+
&:not(:first-child) {
|
|
56
|
+
margin-inline-start: 12px;
|
|
57
|
+
}
|
|
58
|
+
&:not(:last-child) {
|
|
59
|
+
margin-inline-end: 12px;
|
|
52
60
|
}
|
|
53
61
|
}
|
|
54
62
|
}
|
|
@@ -56,7 +64,6 @@ const navLinks = buildNavLinks(Astro.locals.starlightRoute);
|
|
|
56
64
|
@media (min-width: 50rem) {
|
|
57
65
|
.stl-secondary-nav-tabs {
|
|
58
66
|
display: block;
|
|
59
|
-
padding-left: 0.55rem;
|
|
60
67
|
}
|
|
61
68
|
}
|
|
62
69
|
</style>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { StarlightRouteData } from '@astrojs/starlight/route-data';
|
|
2
2
|
import { TABS } from 'virtual:stl-docs-virtual-module';
|
|
3
|
+
import type { StarlightRouteWithStlDocs } from '../../tabsMiddleware';
|
|
3
4
|
|
|
4
5
|
export function buildNavLinks(starlightRoute: StarlightRouteData) {
|
|
5
|
-
|
|
6
|
-
const activeTabIndex =
|
|
6
|
+
const routeData: StarlightRouteWithStlDocs = starlightRoute;
|
|
7
|
+
const activeTabIndex = routeData?._stlDocs?.activeTabIndex;
|
|
7
8
|
|
|
8
9
|
const navLinks = TABS.map((item, index) => ({
|
|
9
10
|
...item,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { base } from 'astro:config/client';
|
|
3
|
+
import { HomeIcon } from 'lucide-react';
|
|
4
|
+
import PaginationLinkQuiet from './PaginationLinkQuiet.astro';
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<PaginationLinkQuiet href={base}>
|
|
8
|
+
<HomeIcon slot="icon" />
|
|
9
|
+
Home
|
|
10
|
+
</PaginationLinkQuiet>
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
---
|
|
2
|
+
import HomeLink from './HomeLink.astro';
|
|
3
|
+
import PaginationLinkEmphasized from './PaginationLinkEmphasized.astro';
|
|
4
|
+
|
|
5
|
+
import { getPrevNextPage } from './util';
|
|
6
|
+
import config from 'virtual:starlight/user-config';
|
|
7
|
+
const { prev, next } = (await getPrevNextPage(Astro.locals.starlightRoute, config.pagination)) ?? {};
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
{
|
|
11
|
+
next || prev ? (
|
|
12
|
+
<div class="pagination-links print:hidden stl-ui-not-prose">
|
|
13
|
+
{/* Previous */}
|
|
14
|
+
{!prev && <HomeLink />}
|
|
15
|
+
{/* TODO: intelligently decide whether or not to emphasize the previous page - including user config option (page level?) */}
|
|
16
|
+
{/* {prev && next && (
|
|
17
|
+
<PaginationLinkQuiet href={prev.href}>
|
|
18
|
+
<ChevronLeftIcon slot="icon" />
|
|
19
|
+
Previous
|
|
20
|
+
</PaginationLinkQuiet>
|
|
21
|
+
)} */}
|
|
22
|
+
{prev && (
|
|
23
|
+
<PaginationLinkEmphasized href={prev.href} direction="prev">
|
|
24
|
+
<h2 slot="page-title">{prev.label}</h2>
|
|
25
|
+
{prev.description && <p slot="page-description">{prev.description}</p>}
|
|
26
|
+
</PaginationLinkEmphasized>
|
|
27
|
+
)}
|
|
28
|
+
|
|
29
|
+
{/* Next */}
|
|
30
|
+
{!next && <HomeLink />}
|
|
31
|
+
{next && (
|
|
32
|
+
<PaginationLinkEmphasized href={next.href} direction="next">
|
|
33
|
+
<h2 slot="page-title">{next.label}</h2>
|
|
34
|
+
{next.description && <p slot="page-description">{next.description}</p>}
|
|
35
|
+
</PaginationLinkEmphasized>
|
|
36
|
+
)}
|
|
37
|
+
</div>
|
|
38
|
+
) : null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
<style is:global>
|
|
42
|
+
@layer starlight.core {
|
|
43
|
+
.pagination-links,
|
|
44
|
+
.pagination-links a,
|
|
45
|
+
.pagination-links a:hover,
|
|
46
|
+
.pagination-links a[rel='next'],
|
|
47
|
+
.link-title {
|
|
48
|
+
all: revert-layer;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.pagination-links {
|
|
53
|
+
--stl-ui-pagination-padding: 8px;
|
|
54
|
+
--stl-ui-pagination-border-radius-inner: var(--stl-ui-layout-border-radius-sml);
|
|
55
|
+
|
|
56
|
+
padding: var(--stl-ui-pagination-padding);
|
|
57
|
+
background-color: var(--stl-color-faint-background);
|
|
58
|
+
border: 1px solid var(--stl-color-border);
|
|
59
|
+
border-radius: calc(var(--stl-ui-pagination-border-radius-inner) + var(--stl-ui-pagination-padding));
|
|
60
|
+
|
|
61
|
+
font-size: var(--stl-typography-scale-sm);
|
|
62
|
+
letter-spacing: normal;
|
|
63
|
+
|
|
64
|
+
display: flex;
|
|
65
|
+
gap: 8px;
|
|
66
|
+
|
|
67
|
+
margin-bottom: 2rem;
|
|
68
|
+
color: inherit; /* stl-ui-not-prose sets color: initial */
|
|
69
|
+
|
|
70
|
+
a {
|
|
71
|
+
border-radius: var(--stl-ui-pagination-border-radius-inner);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.pagination-links__link {
|
|
76
|
+
display: flex;
|
|
77
|
+
border-radius: var(--stl-ui-pagination-border-radius-inner);
|
|
78
|
+
padding: 8px 12px;
|
|
79
|
+
display: flex;
|
|
80
|
+
text-decoration: none;
|
|
81
|
+
align-items: center;
|
|
82
|
+
color: inherit;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.pagination-links__link--emphasized {
|
|
86
|
+
background-color: var(--stl-color-background);
|
|
87
|
+
border: 1px solid var(--stl-color-border);
|
|
88
|
+
flex: 1 1 50%;
|
|
89
|
+
gap: 12px;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.pagination-links__link--quiet {
|
|
93
|
+
flex: 0 1 auto;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.pagination-links__button {
|
|
97
|
+
display: flex;
|
|
98
|
+
align-items: center;
|
|
99
|
+
padding: 8px 14px;
|
|
100
|
+
font-weight: 500;
|
|
101
|
+
line-height: 1;
|
|
102
|
+
|
|
103
|
+
svg {
|
|
104
|
+
width: 16px;
|
|
105
|
+
height: 16px;
|
|
106
|
+
margin-block: -4px;
|
|
107
|
+
margin-inline-start: -6px;
|
|
108
|
+
margin-inline-end: 6px;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
&.pagination-links__link--quiet {
|
|
112
|
+
padding-inline: 22px;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.pagination-links__link__divider {
|
|
117
|
+
border: 0;
|
|
118
|
+
border-inline-start: 1px solid var(--stl-color-border);
|
|
119
|
+
align-self: stretch;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.pagination-links__page-description {
|
|
123
|
+
padding-block: 4px;
|
|
124
|
+
padding-inline-start: 8px;
|
|
125
|
+
padding-inline-end: 2px;
|
|
126
|
+
line-height: 1.5;
|
|
127
|
+
flex: 1 1 50%;
|
|
128
|
+
width: 0;
|
|
129
|
+
|
|
130
|
+
h2,
|
|
131
|
+
p {
|
|
132
|
+
white-space: nowrap;
|
|
133
|
+
overflow: hidden;
|
|
134
|
+
text-overflow: ellipsis;
|
|
135
|
+
}
|
|
136
|
+
h2 {
|
|
137
|
+
font-size: inherit;
|
|
138
|
+
font-weight: 500;
|
|
139
|
+
}
|
|
140
|
+
p {
|
|
141
|
+
font-size: var(--stl-typography-scale-xs);
|
|
142
|
+
color: var(--stl-color-foreground-muted);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
.pagination-links__link--quiet:hover {
|
|
146
|
+
background-color: var(--stl-color-background-hover);
|
|
147
|
+
}
|
|
148
|
+
.pagination-links__link--emphasized:hover {
|
|
149
|
+
border-color: var(--stl-color-border-strong);
|
|
150
|
+
.pagination-links__page-description h2 {
|
|
151
|
+
text-decoration: underline;
|
|
152
|
+
text-decoration-color: var(--stl-color-foreground-reduced);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* “next” link runs the opposite direction of the “previous” link */
|
|
157
|
+
.pagination-links__link:last-child {
|
|
158
|
+
flex-direction: row-reverse;
|
|
159
|
+
|
|
160
|
+
&.pagination-links__button,
|
|
161
|
+
.pagination-links__button {
|
|
162
|
+
flex-direction: row-reverse;
|
|
163
|
+
svg {
|
|
164
|
+
margin-inline-start: 6px;
|
|
165
|
+
margin-inline-end: -6px;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.pagination-links__page-description {
|
|
170
|
+
padding-inline-start: 2px;
|
|
171
|
+
padding-inline-end: 8px;
|
|
172
|
+
text-align: right;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
</style>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { ChevronLeftIcon, ChevronRightIcon } from 'lucide-react';
|
|
3
|
+
const { href, direction } = Astro.props;
|
|
4
|
+
export interface Props {
|
|
5
|
+
href: string;
|
|
6
|
+
direction: 'prev' | 'next';
|
|
7
|
+
}
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<a href={href} class="pagination-links__link pagination-links__link--emphasized">
|
|
11
|
+
<div class="pagination-links__button">
|
|
12
|
+
{{ prev: <ChevronLeftIcon />, next: <ChevronRightIcon /> }[direction]}
|
|
13
|
+
<span>{{ prev: 'Previous', next: 'Next' }[direction]}</span>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
<hr class="pagination-links__link__divider" />
|
|
17
|
+
|
|
18
|
+
<article class="pagination-links__page-description">
|
|
19
|
+
<slot name="page-title" />
|
|
20
|
+
<slot name="page-description" />
|
|
21
|
+
</article>
|
|
22
|
+
</a>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
const { href } = Astro.props;
|
|
3
|
+
export interface Props {
|
|
4
|
+
href: string;
|
|
5
|
+
}
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
<a href={href} class="pagination-links__link pagination-links__button pagination-links__link--quiet">
|
|
9
|
+
<slot name="icon" />
|
|
10
|
+
<span>
|
|
11
|
+
<slot />
|
|
12
|
+
</span>
|
|
13
|
+
</a>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { StarlightRouteData } from '@astrojs/starlight/route-data';
|
|
2
|
+
import { getCollection } from 'astro:content';
|
|
3
|
+
|
|
4
|
+
export type SidebarEntry = StarlightRouteData['sidebar'][number];
|
|
5
|
+
export type SidebarLink = Extract<SidebarEntry, { type: 'link' }>;
|
|
6
|
+
export type SidebarGroup = Extract<SidebarEntry, { type: 'group' }>;
|
|
7
|
+
|
|
8
|
+
export const flattenSidebar = (sidebar: SidebarEntry[]): SidebarLink[] =>
|
|
9
|
+
sidebar.flatMap((e) => (e.type === 'group' ? flattenSidebar(e.entries) : e));
|
|
10
|
+
|
|
11
|
+
function findParentOfSidebarEntry(sidebar: SidebarEntry[], targetEntry: SidebarEntry): SidebarGroup | null {
|
|
12
|
+
for (const entry of sidebar) {
|
|
13
|
+
if (entry.type === 'group') {
|
|
14
|
+
if (entry.entries.includes(targetEntry)) {
|
|
15
|
+
return entry;
|
|
16
|
+
}
|
|
17
|
+
const foundInChild = findParentOfSidebarEntry(entry.entries, targetEntry);
|
|
18
|
+
if (foundInChild) {
|
|
19
|
+
return foundInChild;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function getPrevNextPage(page: StarlightRouteData, paginationEnabled: boolean) {
|
|
27
|
+
// TODO: respect user `next` / `prev` config from frontmatter the way starlight does
|
|
28
|
+
|
|
29
|
+
if (!paginationEnabled) return null;
|
|
30
|
+
|
|
31
|
+
const docsContent = await getCollection('docs');
|
|
32
|
+
const findSidebarLinkInContent = (link: SidebarLink) =>
|
|
33
|
+
docsContent.find((doc) => {
|
|
34
|
+
if (doc.id === 'index' && link.href === '/') return true;
|
|
35
|
+
return doc.id === link.href.replace(/^\//, '').replace(/\/$/, '');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const currentSidebar = page.sidebar;
|
|
39
|
+
|
|
40
|
+
const paginationSequence: (SidebarLink & { description?: string })[] = flattenSidebar(currentSidebar)
|
|
41
|
+
// Remove injected stl-mobile-only-sidebar-item links - TODO: better solution for this
|
|
42
|
+
.filter((link) => !(link.attrs.class ?? '').trim().split(/\s+/).includes('stl-mobile-only-sidebar-item'))
|
|
43
|
+
// Remove data-stldocs-method links from pagination sequence
|
|
44
|
+
.filter((link) => !link.attrs['data-stldocs-method'])
|
|
45
|
+
// Map data-stldocs-overview=readme links so that their name is not just “Overview”
|
|
46
|
+
.map((link) => {
|
|
47
|
+
if (link.attrs['data-stldocs-overview'] && link.label === 'Overview') {
|
|
48
|
+
const parent = findParentOfSidebarEntry(currentSidebar, link);
|
|
49
|
+
if (parent) return { ...link, label: parent.label };
|
|
50
|
+
}
|
|
51
|
+
return link;
|
|
52
|
+
})
|
|
53
|
+
.map((link) => {
|
|
54
|
+
const contentEntry = findSidebarLinkInContent(link);
|
|
55
|
+
if (contentEntry) return { ...link, description: contentEntry.data.description };
|
|
56
|
+
return link;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const currentIndex = paginationSequence.findIndex((e) => e.isCurrent);
|
|
60
|
+
if (currentIndex === -1) return null;
|
|
61
|
+
|
|
62
|
+
const prevIndex = currentIndex > 0 ? currentIndex - 1 : null;
|
|
63
|
+
const nextIndex = currentIndex < paginationSequence.length - 1 ? currentIndex + 1 : null;
|
|
64
|
+
const prevSidebarEntry = prevIndex !== null ? (paginationSequence[prevIndex] ?? null) : null;
|
|
65
|
+
const nextSidebarEntry = nextIndex !== null ? (paginationSequence[nextIndex] ?? null) : null;
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
prev: prevSidebarEntry,
|
|
69
|
+
next: nextSidebarEntry,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@stainless-api/ui-primitives/scripts';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AstroIntegration } from 'astro';
|
|
2
|
+
import type { StarlightPlugin } from '@astrojs/starlight/types';
|
|
3
|
+
|
|
4
|
+
export const disableCalloutSyntaxAstroIntegration = {
|
|
5
|
+
name: 'stl-starlight-remove-callout-syntax',
|
|
6
|
+
hooks: {
|
|
7
|
+
'astro:config:setup': ({ config: astroConfig }) => {
|
|
8
|
+
// Remove starlight callout syntax in favor of our own callout component
|
|
9
|
+
// updateConfig always deeply merges arrays so we need to mutate remarkPlugins directly
|
|
10
|
+
// in order to remove plugins that starlight added
|
|
11
|
+
astroConfig.markdown.remarkPlugins = astroConfig.markdown.remarkPlugins.filter((plugin, i, arr) => {
|
|
12
|
+
if (typeof plugin !== 'function') return true;
|
|
13
|
+
// remove:
|
|
14
|
+
// 1. remarkDirective plugin
|
|
15
|
+
if (plugin.name === 'remarkDirective') return false;
|
|
16
|
+
// 2. directly followed by remarkAsides plugin (inner function named 'attacher')
|
|
17
|
+
if (plugin.name === 'attacher') {
|
|
18
|
+
const prev = arr[i - 1];
|
|
19
|
+
if (typeof prev === 'function' && prev.name === 'remarkDirective') return false;
|
|
20
|
+
}
|
|
21
|
+
// 3. remarkDirectivesRestoration plugin
|
|
22
|
+
if (plugin.name === 'remarkDirectivesRestoration') return false;
|
|
23
|
+
return true;
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
} satisfies AstroIntegration;
|
|
28
|
+
|
|
29
|
+
export const disableCalloutSyntaxStarlightPlugin = {
|
|
30
|
+
name: 'stl-starlight-remove-callout-syntax',
|
|
31
|
+
hooks: {
|
|
32
|
+
'config:setup': ({ addIntegration }) => {
|
|
33
|
+
addIntegration(disableCalloutSyntaxAstroIntegration);
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
} satisfies StarlightPlugin;
|
package/stl-docs/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import starlight from '@astrojs/starlight';
|
|
2
2
|
import react from '@astrojs/react';
|
|
3
|
-
import {
|
|
3
|
+
import type { StarlightPlugin } from '@astrojs/starlight/types';
|
|
4
|
+
import { disableCalloutSyntaxStarlightPlugin } from './disableCalloutSyntax';
|
|
4
5
|
|
|
5
6
|
import type { AstroIntegration } from 'astro';
|
|
6
7
|
|
|
@@ -16,11 +17,17 @@ import {
|
|
|
16
17
|
type StarlightSidebarConfig,
|
|
17
18
|
} from './loadStlDocsConfig';
|
|
18
19
|
import { buildVirtualModuleString } from '../shared/virtualModule';
|
|
19
|
-
|
|
20
|
-
import
|
|
20
|
+
import type * as StlDocsVirtualModule from 'virtual:stl-docs-virtual-module';
|
|
21
|
+
import { resolveSrcFile } from '../resolveSrcFile';
|
|
22
|
+
import { stainlessDocsMarkdownRenderer } from './proseMarkdown/proseMarkdownIntegration';
|
|
23
|
+
import { setSharedLogger } from '../shared/getSharedLogger';
|
|
24
|
+
import { stainlessDocsAlgoliaProseIndexing, stainlessDocsVectorProseIndexing } from './proseSearchIndexing';
|
|
25
|
+
import { stainlessStarlight } from '../plugin';
|
|
21
26
|
|
|
22
27
|
export * from '../plugin';
|
|
23
28
|
|
|
29
|
+
const COMPONENTS_FOLDER = '/stl-docs/components';
|
|
30
|
+
|
|
24
31
|
function stainlessDocsStarlightIntegration(config: NormalizedStainlessDocsConfig) {
|
|
25
32
|
// We transform our tabs into a Starlight sidebar
|
|
26
33
|
// This gives them all the built-in features of Starlight (eg. auto-generated entries by directory)
|
|
@@ -40,21 +47,40 @@ function stainlessDocsStarlightIntegration(config: NormalizedStainlessDocsConfig
|
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
type ComponentOverrides = StarlightConfigDefined['components'];
|
|
43
|
-
const plugins = [...config.starlightCompat.plugins];
|
|
44
|
-
|
|
45
50
|
const componentOverrides: ComponentOverrides = {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
PageFrame: resolveSrcFile(COMPONENTS_FOLDER, './PageFrame.astro'),
|
|
52
|
+
|
|
53
|
+
Head: resolveSrcFile(COMPONENTS_FOLDER, './Head.astro'),
|
|
54
|
+
Header: resolveSrcFile(COMPONENTS_FOLDER, './Header.astro'),
|
|
55
|
+
ThemeProvider: resolveSrcFile(COMPONENTS_FOLDER, './ThemeProvider.astro'),
|
|
56
|
+
ThemeSelect: resolveSrcFile(COMPONENTS_FOLDER, './ThemeSelect.astro'),
|
|
57
|
+
|
|
58
|
+
Sidebar: resolveSrcFile(COMPONENTS_FOLDER, './sidebars/BaseSidebar.astro'),
|
|
59
|
+
ContentPanel: resolveSrcFile(COMPONENTS_FOLDER, './content-panel/ContentPanel.astro'),
|
|
60
|
+
TableOfContents: resolveSrcFile(COMPONENTS_FOLDER, './TableOfContents.astro'),
|
|
61
|
+
|
|
62
|
+
PageTitle: resolveSrcFile(COMPONENTS_FOLDER, './PageTitle.astro'),
|
|
63
|
+
Pagination: resolveSrcFile(COMPONENTS_FOLDER, './pagination/Pagination.astro'),
|
|
50
64
|
};
|
|
51
65
|
|
|
66
|
+
const plugins: StarlightPlugin[] = [
|
|
67
|
+
// Disable starlight callout syntax in favor of our own component
|
|
68
|
+
disableCalloutSyntaxStarlightPlugin,
|
|
69
|
+
];
|
|
70
|
+
|
|
52
71
|
if (config.apiReference !== null) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
plugins.push(
|
|
73
|
+
stainlessStarlight({
|
|
74
|
+
...config.apiReference,
|
|
75
|
+
contextMenu: config.contextMenu,
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
componentOverrides.Sidebar = resolveSrcFile(COMPONENTS_FOLDER, './sidebars/SDKSelectSidebar.astro');
|
|
79
|
+
componentOverrides.Search = resolveSrcFile('/plugin/components/search/Search.astro');
|
|
56
80
|
}
|
|
57
81
|
|
|
82
|
+
plugins.push(...config.starlightCompat.plugins, ...config.plugins.map((p) => p(config)));
|
|
83
|
+
|
|
58
84
|
// TODO: re-add once we figure out what to do with the client router
|
|
59
85
|
// if (config.enableClientRouter) {
|
|
60
86
|
// // logger.info(`Client router is enabled`);
|
|
@@ -63,6 +89,8 @@ function stainlessDocsStarlightIntegration(config: NormalizedStainlessDocsConfig
|
|
|
63
89
|
// // logger.info(`Client router is disabled`);
|
|
64
90
|
// }
|
|
65
91
|
|
|
92
|
+
const userExpressiveCode = typeof config.expressiveCode === 'object' ? config.expressiveCode : {};
|
|
93
|
+
|
|
66
94
|
return starlight({
|
|
67
95
|
...config.starlightPassThrough,
|
|
68
96
|
sidebar,
|
|
@@ -86,68 +114,104 @@ function stainlessDocsStarlightIntegration(config: NormalizedStainlessDocsConfig
|
|
|
86
114
|
setupNavLinksInitial();
|
|
87
115
|
`,
|
|
88
116
|
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
117
|
+
],
|
|
118
|
+
routeMiddleware: [
|
|
119
|
+
...config.starlightCompat.routeMiddleware,
|
|
120
|
+
resolveSrcFile('/stl-docs/tabsMiddleware.ts'),
|
|
121
|
+
],
|
|
122
|
+
customCss: [resolveSrcFile('/theme.css'), ...config.customCss],
|
|
123
|
+
|
|
124
|
+
expressiveCode: {
|
|
125
|
+
...userExpressiveCode,
|
|
126
|
+
themes: userExpressiveCode.themes ?? ['github-light', 'github-dark'],
|
|
127
|
+
styleOverrides: {
|
|
128
|
+
...userExpressiveCode.styleOverrides,
|
|
129
|
+
textMarkers: {
|
|
130
|
+
insBackground: 'var(--stl-color-green-muted-background)',
|
|
131
|
+
insBorderColor: 'var(--stl-color-green-border)',
|
|
132
|
+
insDiffIndicatorColor: 'var(--stl-color-green-foreground-reduced)',
|
|
133
|
+
|
|
134
|
+
delBackground: 'var(--stl-color-red-muted-background)',
|
|
135
|
+
delBorderColor: 'var(--stl-color-red-border)',
|
|
136
|
+
delDiffIndicatorColor: 'var(--stl-color-red-foreground-reduced)',
|
|
137
|
+
|
|
138
|
+
markBackground: 'var(--stl-color-blue-muted-background)',
|
|
139
|
+
markBorderColor: 'var(--stl-color-blue-border)',
|
|
140
|
+
...userExpressiveCode.styleOverrides?.textMarkers,
|
|
99
141
|
},
|
|
100
142
|
},
|
|
101
|
-
|
|
102
|
-
routeMiddleware: [...config.starlightCompat.routeMiddleware, '@stainless-api/docs/tabsMiddleware'],
|
|
103
|
-
customCss: ['@stainless-api/docs/theme', ...config.customCss],
|
|
143
|
+
},
|
|
104
144
|
plugins,
|
|
105
145
|
});
|
|
106
146
|
}
|
|
107
147
|
|
|
108
|
-
function stainlessDocsIntegration(
|
|
109
|
-
|
|
148
|
+
function stainlessDocsIntegration(
|
|
149
|
+
config: NormalizedStainlessDocsConfig,
|
|
150
|
+
apiReferenceBasePath: string | null,
|
|
151
|
+
): AstroIntegration {
|
|
152
|
+
const virtualModules = new Map(
|
|
153
|
+
Object.entries({
|
|
154
|
+
'virtual:stl-docs-virtual-module': buildVirtualModuleString({
|
|
155
|
+
TABS: config.tabs,
|
|
156
|
+
SPLIT_TABS_ENABLED: config.splitTabsEnabled,
|
|
157
|
+
HEADER_LINKS: config.header.links,
|
|
158
|
+
HEADER_LAYOUT: config.header.layout,
|
|
159
|
+
ENABLE_CLIENT_ROUTER: config.enableClientRouter,
|
|
160
|
+
API_REFERENCE_BASE_PATH: apiReferenceBasePath,
|
|
161
|
+
ENABLE_PROSE_MARKDOWN_RENDERING: config.enableProseMarkdownRendering,
|
|
162
|
+
ENABLE_CONTEXT_MENU: config.contextMenu, // TODO: do not duplicate this between both virtual modules
|
|
163
|
+
RENDER_PAGE_DESCRIPTIONS: config.renderPageDescriptions,
|
|
164
|
+
} satisfies typeof StlDocsVirtualModule),
|
|
165
|
+
|
|
166
|
+
'virtual:stl-docs/components/AiChat.tsx': `
|
|
167
|
+
${
|
|
168
|
+
config.aiChat
|
|
169
|
+
? `export { default } from ${JSON.stringify(config.aiChat.chatComponentPath)};`
|
|
170
|
+
: // export null when no AI chat component is provided
|
|
171
|
+
`export default null;`
|
|
172
|
+
}
|
|
173
|
+
export const STAINLESS_PROJECT = ${config.apiReference ? JSON.stringify(config.apiReference.stainlessProject) : 'undefined'};
|
|
174
|
+
`,
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
|
|
110
178
|
// The '\0' prefix tells Vite “this is a virtual module” and prevents it from being resolved again.
|
|
111
|
-
const
|
|
179
|
+
const resolveVirtualModuleId = (id: string) => `\0${id}`;
|
|
112
180
|
let redirects: NormalizedRedirectConfig | null = null;
|
|
113
181
|
|
|
114
182
|
return {
|
|
115
|
-
name: 'stl-docs-
|
|
183
|
+
name: 'stl-docs-astro',
|
|
116
184
|
hooks: {
|
|
117
185
|
'astro:config:setup': ({ updateConfig, command, config: astroConfig }) => {
|
|
118
|
-
//
|
|
119
|
-
//
|
|
186
|
+
// we only handle redirects for builds
|
|
187
|
+
// in dev, Astro handles them for us
|
|
120
188
|
if (command === 'build' && astroConfig.redirects) {
|
|
121
189
|
redirects = normalizeRedirects(astroConfig.redirects);
|
|
122
190
|
}
|
|
123
191
|
|
|
124
192
|
updateConfig({
|
|
125
193
|
vite: {
|
|
126
|
-
ssr: {
|
|
127
|
-
noExternal: ['@stainless-api/ui-primitives'],
|
|
128
|
-
},
|
|
129
|
-
optimizeDeps: { include: ['@stainless-api/ui-primitives'] },
|
|
130
194
|
plugins: [
|
|
131
195
|
{
|
|
132
196
|
name: 'stl-docs-vite',
|
|
133
197
|
resolveId(id) {
|
|
134
|
-
if (id
|
|
135
|
-
return resolvedId;
|
|
136
|
-
}
|
|
198
|
+
if (virtualModules.has(id)) return resolveVirtualModuleId(id);
|
|
137
199
|
},
|
|
138
200
|
load(id) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
TABS: config.tabs,
|
|
142
|
-
SPLIT_TABS_ENABLED: config.splitTabsEnabled,
|
|
143
|
-
HEADER_LINKS: config.header.links,
|
|
144
|
-
HEADER_LAYOUT: config.header.layout,
|
|
145
|
-
ENABLE_CLIENT_ROUTER: config.enableClientRouter,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
201
|
+
const bare = id.replace(/^\0/, '');
|
|
202
|
+
if (virtualModules.has(bare)) return virtualModules.get(bare);
|
|
148
203
|
},
|
|
149
204
|
},
|
|
150
205
|
],
|
|
206
|
+
optimizeDeps: {
|
|
207
|
+
include: config.aiChat
|
|
208
|
+
? [
|
|
209
|
+
'@stainless-api/docs-ai-chat > motion',
|
|
210
|
+
'@stainless-api/docs-ai-chat > react-markdown',
|
|
211
|
+
'@stainless-api/docs-ai-chat > react-syntax-highlighter',
|
|
212
|
+
]
|
|
213
|
+
: [],
|
|
214
|
+
},
|
|
151
215
|
},
|
|
152
216
|
build: {
|
|
153
217
|
...astroConfig.build,
|
|
@@ -158,7 +222,7 @@ function stainlessDocsIntegration(config: NormalizedStainlessDocsConfig): AstroI
|
|
|
158
222
|
'astro:build:done': ({ dir }) => {
|
|
159
223
|
if (redirects !== null) {
|
|
160
224
|
const stainlessDir = join(dir.pathname, '_stainless');
|
|
161
|
-
mkdirSync(stainlessDir);
|
|
225
|
+
mkdirSync(stainlessDir, { recursive: true });
|
|
162
226
|
const outputPath = join(stainlessDir, 'redirects.json');
|
|
163
227
|
writeFileSync(outputPath, JSON.stringify(redirects, null, 2), {
|
|
164
228
|
encoding: 'utf-8',
|
|
@@ -169,7 +233,18 @@ function stainlessDocsIntegration(config: NormalizedStainlessDocsConfig): AstroI
|
|
|
169
233
|
};
|
|
170
234
|
}
|
|
171
235
|
|
|
172
|
-
|
|
236
|
+
function sharedLoggerIntegration(): AstroIntegration {
|
|
237
|
+
return {
|
|
238
|
+
name: 'stainless',
|
|
239
|
+
hooks: {
|
|
240
|
+
'astro:config:setup': ({ logger }) => {
|
|
241
|
+
setSharedLogger(logger);
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function stainlessDocs(config: StainlessDocsUserConfig): StarlightPlugin[] {
|
|
173
248
|
const normalizedConfigResult = parseStlDocsConfig(config);
|
|
174
249
|
if (normalizedConfigResult.result === 'error') {
|
|
175
250
|
// TODO: would be good to use the astro logger somehow
|
|
@@ -178,9 +253,25 @@ export function stainlessDocs(config: StainlessDocsUserConfig) {
|
|
|
178
253
|
}
|
|
179
254
|
const normalizedConfig = normalizedConfigResult.config;
|
|
180
255
|
|
|
256
|
+
// TODO: need to refactor this, but this allows us to get the base path for the API reference _if_ it exists
|
|
257
|
+
// if it doesn't exist, the value of basePath is null.
|
|
258
|
+
// the stl-starlight virtual module has base path, but it's not available when there's no API reference
|
|
259
|
+
const hasApiReference = normalizedConfig.apiReference !== null;
|
|
260
|
+
let apiReferenceBasePath: string | null = null;
|
|
261
|
+
if (hasApiReference) {
|
|
262
|
+
apiReferenceBasePath = normalizedConfig.apiReference?.basePath ?? '/api';
|
|
263
|
+
}
|
|
264
|
+
|
|
181
265
|
return [
|
|
266
|
+
sharedLoggerIntegration(), // this **must** be first so it can set the shared logger used by our other integrations
|
|
182
267
|
react(),
|
|
183
268
|
stainlessDocsStarlightIntegration(normalizedConfig),
|
|
184
|
-
stainlessDocsIntegration(normalizedConfig),
|
|
269
|
+
stainlessDocsIntegration(normalizedConfig, apiReferenceBasePath),
|
|
270
|
+
stainlessDocsMarkdownRenderer({
|
|
271
|
+
enabled: normalizedConfig.enableProseMarkdownRendering,
|
|
272
|
+
apiReferenceBasePath,
|
|
273
|
+
}),
|
|
274
|
+
stainlessDocsAlgoliaProseIndexing({ apiReferenceBasePath }),
|
|
275
|
+
stainlessDocsVectorProseIndexing(normalizedConfig, apiReferenceBasePath),
|
|
185
276
|
];
|
|
186
277
|
}
|