@stainless-api/docs 0.1.0-beta.127 → 0.1.0-beta.129

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 CHANGED
@@ -1,5 +1,24 @@
1
1
  # @stainless-api/docs
2
2
 
3
+ ## 0.1.0-beta.129
4
+
5
+ ### Minor Changes
6
+
7
+ - 966ec34: Fixes nav dropdown logic
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [966ec34]
12
+ - @stainless-api/ui-primitives@0.1.0-beta.52
13
+ - @stainless-api/docs-search@0.1.0-beta.45
14
+ - @stainless-api/docs-ui@0.1.0-beta.92
15
+
16
+ ## 0.1.0-beta.128
17
+
18
+ ### Patch Changes
19
+
20
+ - e8a95f4: Revert “Fix getProsePages treating all pages as prose when API reference basePath is empty”
21
+
3
22
  ## 0.1.0-beta.127
4
23
 
5
24
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stainless-api/docs",
3
- "version": "0.1.0-beta.127",
3
+ "version": "0.1.0-beta.129",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -61,9 +61,9 @@
61
61
  "vite-plugin-prebundle-workers": "^0.2.0",
62
62
  "web-worker": "^1.5.0",
63
63
  "yaml": "^2.8.3",
64
- "@stainless-api/docs-search": "0.1.0-beta.44",
65
- "@stainless-api/docs-ui": "0.1.0-beta.91",
66
- "@stainless-api/ui-primitives": "0.1.0-beta.51"
64
+ "@stainless-api/docs-search": "0.1.0-beta.45",
65
+ "@stainless-api/docs-ui": "0.1.0-beta.92",
66
+ "@stainless-api/ui-primitives": "0.1.0-beta.52"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@astrojs/check": "^0.9.8",
package/plugin/index.ts CHANGED
@@ -30,7 +30,7 @@ import prebundleWorkers from 'vite-plugin-prebundle-workers';
30
30
  import { SpecLoader, startSpecLoader } from './specs';
31
31
 
32
32
  import type * as ReferenceSidebarsVirtualModule from 'virtual:stl-starlight-reference-sidebars';
33
- import { generateMissingRouteList, generateRouteList } from '@stainless-api/docs-ui/routing';
33
+ import { generateMissingRouteList } from '@stainless-api/docs-ui/routing';
34
34
  import { buildAlgoliaIndex } from './buildAlgoliaIndex';
35
35
 
36
36
  export { generateAPILink } from './generateAPIReferenceLink';
@@ -357,26 +357,13 @@ function stlStarlightAstroIntegration(pluginConfig: NormalizedStainlessStarlight
357
357
  collectedErrors = null;
358
358
  }
359
359
 
360
- const specComposite = await resolveSpecs();
361
-
362
- // TODO: (multi-spec) support multiple specs
363
- const spec = specComposite.listUniqueSpecs()[0]!.data.sdkJson;
364
-
365
- const basePrefixInOutput = path.posix.join(astroBase, pluginConfig.basePath).replace(/^\/+/, '');
366
- const routeList = generateRouteList({ spec });
367
- const apiReferencePages = [
368
- // overview page
369
- path.posix.join(basePrefixInOutput, 'index.html'),
370
- // all route pages
371
- ...routeList.map((r) => path.posix.join(basePrefixInOutput, r.slug, 'index.html')),
372
- ];
373
-
374
360
  const manifest = {
375
361
  astroBase,
376
- apiReferencePages,
377
362
  };
378
363
  await writeFile(path.join(stainlessDir, 'stl-manifest.json'), JSON.stringify(manifest, null, 2));
379
364
 
365
+ const specComposite = await resolveSpecs();
366
+
380
367
  await buildAlgoliaIndex({
381
368
  specComposite,
382
369
  logger,
@@ -388,6 +375,9 @@ function stlStarlightAstroIntegration(pluginConfig: NormalizedStainlessStarlight
388
375
  // in this file so Cloudflare can serve them with a 404 status. These pages display helpful information
389
376
  // about the missing method and provide links to SDKs where it is available.
390
377
 
378
+ // TODO: (multi-spec) support multiple specs
379
+ const spec = specComposite.listUniqueSpecs()[0]!.data.sdkJson;
380
+
391
381
  const missingRoutes = generateMissingRouteList({
392
382
  spec,
393
383
  basePath: path.posix.join(astroBase, pluginConfig.basePath),
@@ -1,8 +1,6 @@
1
- import { readdir, readFile } from 'fs/promises';
1
+ import { readdir } from 'fs/promises';
2
2
  import { join, relative } from 'path';
3
3
 
4
- const MANIFEST_PATH = '_stainless/stl-manifest.json';
5
-
6
4
  /**
7
5
  * Get all prose pages after a build, by reading all HTML files from the
8
6
  * given output directory, and not from assets.
@@ -12,11 +10,14 @@ const MANIFEST_PATH = '_stainless/stl-manifest.json';
12
10
  * Other astro integrations may hijack the "[...slug]" entrypoint, and any files
13
11
  * previously in the [...slug] asset map entry would be lost (this is where starlight stores
14
12
  * its prose HTML files).
15
- *
16
- * API reference pages are excluded using the manifest written by the API
17
- * reference plugin at build time, rather than guessing based on path prefix.
18
13
  */
19
- export async function getProsePages({ outputBasePath }: { outputBasePath: string }): Promise<string[]> {
14
+ export async function getProsePages({
15
+ apiReferenceBasePath,
16
+ outputBasePath,
17
+ }: {
18
+ apiReferenceBasePath: string | null;
19
+ outputBasePath: string;
20
+ }): Promise<string[]> {
20
21
  const allFiles = await readdir(outputBasePath, {
21
22
  recursive: true,
22
23
  withFileTypes: true,
@@ -26,22 +27,15 @@ export async function getProsePages({ outputBasePath }: { outputBasePath: string
26
27
  .filter((file) => file.isFile() && file.name.endsWith('.html'))
27
28
  .map((file) => join(file.parentPath, file.name));
28
29
 
29
- const apiReferencePages = await readApiReferencePagesFromManifest(outputBasePath);
30
- if (apiReferencePages.size === 0) return htmlFiles;
31
-
32
- return htmlFiles.filter((absPath) => {
30
+ if (!apiReferenceBasePath) return htmlFiles;
31
+ // Normalize by removing leading/trailing slashes from apiReferenceBasePath
32
+ const normalizedApiPath = apiReferenceBasePath.replace(/^\/+/g, '').replace(/\/+$/g, '');
33
+ const pagesToRender = htmlFiles.filter((absPath) => {
33
34
  const relPath = relative(outputBasePath, absPath);
34
- return !apiReferencePages.has(relPath);
35
+ // Filter out API reference pages
36
+ if (relPath === normalizedApiPath || relPath.startsWith(`${normalizedApiPath}/`)) return false;
37
+ return true;
35
38
  });
36
- }
37
39
 
38
- async function readApiReferencePagesFromManifest(outputBasePath: string): Promise<Set<string>> {
39
- try {
40
- const raw = await readFile(join(outputBasePath, MANIFEST_PATH), 'utf-8');
41
- const manifest = JSON.parse(raw) as { apiReferencePages?: string[] };
42
- const pages = manifest.apiReferencePages ?? [];
43
- return new Set(pages);
44
- } catch {
45
- return new Set();
46
- }
40
+ return pagesToRender;
47
41
  }
@@ -1,29 +1,33 @@
1
1
  ---
2
- import { Dropdown } from '@stainless-api/docs/components';
3
- import { buildNavLinks } from './buildNavLinks';
4
2
  import { ChevronsUpDownIcon } from 'lucide-react';
3
+ import { Dropdown } from '@stainless-api/docs/components';
5
4
 
6
- const navLinks = buildNavLinks(Astro.locals.starlightRoute);
5
+ import type { NavLink } from './buildNavLinks';
7
6
 
8
- const buttonText = (navLinks.find((item) => item.active) ?? navLinks[0]!).label;
7
+ export type Props = {
8
+ links: NavLink[];
9
+ currentItem: NavLink | null;
10
+ };
9
11
  ---
10
12
 
11
13
  <Dropdown id="nav-dropdown" className="nav-dropdown-root">
12
14
  <Dropdown.Trigger>
13
- <Dropdown.TriggerSelectedItem>{buttonText}</Dropdown.TriggerSelectedItem>
15
+ <Dropdown.TriggerSelectedItem>
16
+ {Astro.props.currentItem ? Astro.props.currentItem.label : 'Navigation'}
17
+ </Dropdown.TriggerSelectedItem>
14
18
  <Dropdown.TriggerIcon>
15
19
  <ChevronsUpDownIcon size={16} />
16
20
  </Dropdown.TriggerIcon>
17
21
  </Dropdown.Trigger>
18
22
  <Dropdown.Menu className="dropdown-menu">
19
23
  {
20
- navLinks.map((item) => (
24
+ Astro.props.links.map((item) => (
21
25
  <Dropdown.MenuItem
22
26
  key={item.link}
23
27
  href={item.link}
24
28
  className="dropdown-item"
25
29
  value={item.label}
26
- isSelected={item.label === buttonText}
30
+ isSelected={item.active}
27
31
  >
28
32
  {item.label}
29
33
  <Dropdown.MenuItemTemplate>{item.label}</Dropdown.MenuItemTemplate>
@@ -39,6 +43,7 @@ const buttonText = (navLinks.find((item) => item.active) ?? navLinks[0]!).label;
39
43
 
40
44
  document.addEventListener(getPageLoadEvent(), () => {
41
45
  initDropdown({
46
+ initialValue: null,
42
47
  root: document.getElementById('nav-dropdown'),
43
48
  });
44
49
  });
@@ -5,6 +5,8 @@ import NavDropdown from './NavDropdown.astro';
5
5
  import clsx from 'clsx';
6
6
 
7
7
  const navLinks = buildNavLinks(Astro.locals.starlightRoute);
8
+
9
+ const currentItem = navLinks.find((item) => item.active) ?? null;
8
10
  ---
9
11
 
10
12
  <div id="nav-links-container" class="nav-links-container">
@@ -26,7 +28,7 @@ const navLinks = buildNavLinks(Astro.locals.starlightRoute);
26
28
  </ul>
27
29
  </div>
28
30
  <div class="mobile-nav-dropdown" data-mobile-only>
29
- <NavDropdown />
31
+ {navLinks.length > 0 && <NavDropdown links={navLinks} currentItem={currentItem} />}
30
32
  </div>
31
33
  </div>
32
34
 
@@ -13,3 +13,5 @@ export function buildNavLinks(starlightRoute: StarlightRouteData) {
13
13
 
14
14
  return navLinks;
15
15
  }
16
+
17
+ export type NavLink = ReturnType<typeof buildNavLinks>[number];
package/stl-docs/index.ts CHANGED
@@ -303,17 +303,17 @@ export function stainlessDocs(config: StainlessDocsUserConfig): AstroIntegration
303
303
  stainlessDocsIntegration(normalizedConfig, apiReferenceBasePath),
304
304
  conditionalIntegration({
305
305
  condition: !config.experimental?.disableProseMarkdownRendering,
306
- integration: stainlessDocsMarkdownRenderer(),
306
+ integration: stainlessDocsMarkdownRenderer({ apiReferenceBasePath }),
307
307
  reason: 'disabled by experimental config "disableProseMarkdownRendering"',
308
308
  }),
309
309
  conditionalIntegration({
310
310
  condition: !config.experimental?.disableStainlessProseIndexing,
311
- integration: stainlessDocsAlgoliaProseIndexing(),
311
+ integration: stainlessDocsAlgoliaProseIndexing({ apiReferenceBasePath }),
312
312
  reason: 'disabled by experimental config "disableStainlessProseIndexing"',
313
313
  }),
314
314
  conditionalIntegration({
315
315
  condition: !config.experimental?.disableStainlessProseIndexing,
316
- integration: stainlessDocsVectorProseIndexing(normalizedConfig),
316
+ integration: stainlessDocsVectorProseIndexing(normalizedConfig, apiReferenceBasePath),
317
317
  reason: 'disabled by experimental config "disableStainlessProseIndexing"',
318
318
  }),
319
319
  ];
@@ -304,7 +304,10 @@ async function syncProseDocuments(opts: {
304
304
 
305
305
  // ─── Astro integration ──────────────────────────────────────────────
306
306
 
307
- export function stainlessDocsVectorProseIndexing(config: NormalizedStainlessDocsConfig): AstroIntegration {
307
+ export function stainlessDocsVectorProseIndexing(
308
+ config: NormalizedStainlessDocsConfig,
309
+ apiReferenceBasePath: string | null,
310
+ ): AstroIntegration {
308
311
  return {
309
312
  name: 'stl-docs-prose-indexing',
310
313
  hooks: {
@@ -328,7 +331,7 @@ export function stainlessDocsVectorProseIndexing(config: NormalizedStainlessDocs
328
331
  return;
329
332
  }
330
333
 
331
- const pages = await getProsePages({ outputBasePath });
334
+ const pages = await getProsePages({ apiReferenceBasePath, outputBasePath });
332
335
  if (pages.length === 0) {
333
336
  logger.info('No prose pages found to index for vector search');
334
337
  return;
@@ -6,7 +6,11 @@ import { getSharedLogger } from '../../shared/getSharedLogger';
6
6
  import { bold } from '../../shared/terminalUtils';
7
7
  import { getProsePages } from '../../shared/getProsePages';
8
8
 
9
- export function stainlessDocsMarkdownRenderer(): AstroIntegration {
9
+ export function stainlessDocsMarkdownRenderer({
10
+ apiReferenceBasePath,
11
+ }: {
12
+ apiReferenceBasePath: string | null;
13
+ }): AstroIntegration {
10
14
  return {
11
15
  name: 'stl-docs-md',
12
16
  hooks: {
@@ -19,7 +23,7 @@ export function stainlessDocsMarkdownRenderer(): AstroIntegration {
19
23
  'astro:build:done': async ({ logger: localLogger, dir }) => {
20
24
  const logger = getSharedLogger({ fallback: localLogger });
21
25
  const outputBasePath = dir.pathname;
22
- const pagesToRender = await getProsePages({ outputBasePath });
26
+ const pagesToRender = await getProsePages({ apiReferenceBasePath, outputBasePath });
23
27
 
24
28
  logger.info(bold(`Building ${pagesToRender.length} Markdown pages for prose content`));
25
29
 
@@ -174,7 +174,11 @@ export function* indexHTML(
174
174
  }
175
175
  }
176
176
 
177
- export function stainlessDocsAlgoliaProseIndexing(): AstroIntegration {
177
+ export function stainlessDocsAlgoliaProseIndexing({
178
+ apiReferenceBasePath,
179
+ }: {
180
+ apiReferenceBasePath: string | null;
181
+ }): AstroIntegration {
178
182
  return {
179
183
  name: 'stl-docs-prose-indexing',
180
184
  hooks: {
@@ -193,7 +197,7 @@ export function stainlessDocsAlgoliaProseIndexing(): AstroIntegration {
193
197
  return;
194
198
  }
195
199
 
196
- const pagesToRender = await getProsePages({ outputBasePath });
200
+ const pagesToRender = await getProsePages({ apiReferenceBasePath, outputBasePath });
197
201
  logger.info(bold(`Indexing ${pagesToRender.length} prose pages for algolia search`));
198
202
 
199
203
  const objects = [];
@@ -1,130 +0,0 @@
1
- import type { Dirent } from 'fs';
2
- import { describe, expect, it, vi, beforeEach } from 'vitest';
3
- import { join } from 'path';
4
-
5
- vi.mock('fs/promises', () => ({
6
- readdir: vi.fn(),
7
- readFile: vi.fn(),
8
- }));
9
-
10
- import { readdir, readFile } from 'fs/promises';
11
- import { getProsePages } from './getProsePages';
12
-
13
- const mockedReaddir = vi.mocked(readdir);
14
- const mockedReadFile = vi.mocked(readFile);
15
-
16
- function fakeDirent(parentPath: string, name: string, isFile = true): Dirent {
17
- return {
18
- name,
19
- parentPath,
20
- path: parentPath,
21
- isFile: () => isFile,
22
- isDirectory: () => !isFile,
23
- isBlockDevice: () => false,
24
- isCharacterDevice: () => false,
25
- isFIFO: () => false,
26
- isSocket: () => false,
27
- isSymbolicLink: () => false,
28
- } as Dirent;
29
- }
30
-
31
- function stubManifest(apiReferencePages: string[]) {
32
- mockedReadFile.mockResolvedValue(JSON.stringify({ astroBase: '/', apiReferencePages }));
33
- }
34
-
35
- function stubReaddir(dirents: Dirent[]) {
36
- // readdir has many overloads; cast to match the withFileTypes variant
37
- mockedReaddir.mockResolvedValue(dirents as unknown as Awaited<ReturnType<typeof readdir>>);
38
- }
39
-
40
- describe('getProsePages', () => {
41
- beforeEach(() => {
42
- vi.resetAllMocks();
43
- // Default: no manifest
44
- mockedReadFile.mockRejectedValue(new Error('ENOENT'));
45
- });
46
-
47
- it('does not return API reference pages as prose when basePath is ""', async () => {
48
- stubManifest(['resources/users/index.html', 'resources/users/methods/create/index.html']);
49
- stubReaddir([
50
- fakeDirent('/out/guides', 'intro.html'),
51
- fakeDirent('/out/resources/users', 'index.html'),
52
- fakeDirent('/out/resources/users/methods/create', 'index.html'),
53
- ]);
54
-
55
- const result = await getProsePages({ outputBasePath: '/out' });
56
-
57
- // resources/users/** are API reference pages, not prose
58
- expect(result).not.toContainEqual(join('/out/resources/users', 'index.html'));
59
- expect(result).not.toContainEqual(join('/out/resources/users/methods/create', 'index.html'));
60
- expect(result).toContainEqual(join('/out/guides', 'intro.html'));
61
- });
62
-
63
- it('returns all HTML files when no manifest exists', async () => {
64
- stubReaddir([fakeDirent('/out', 'index.html'), fakeDirent('/out/guides', 'intro.html')]);
65
-
66
- const result = await getProsePages({ outputBasePath: '/out' });
67
-
68
- expect(result).toEqual([join('/out', 'index.html'), join('/out/guides', 'intro.html')]);
69
- });
70
-
71
- it('returns all HTML files when manifest has empty apiReferencePages', async () => {
72
- stubManifest([]);
73
- stubReaddir([fakeDirent('/out', 'index.html'), fakeDirent('/out/guides', 'intro.html')]);
74
-
75
- const result = await getProsePages({ outputBasePath: '/out' });
76
-
77
- expect(result).toEqual([join('/out', 'index.html'), join('/out/guides', 'intro.html')]);
78
- });
79
-
80
- it('excludes files listed in the manifest', async () => {
81
- stubManifest(['api/resources/users/index.html', 'api/resources/users/methods/create/index.html']);
82
- stubReaddir([
83
- fakeDirent('/out', 'index.html'),
84
- fakeDirent('/out/guides', 'intro.html'),
85
- fakeDirent('/out/api/resources/users', 'index.html'),
86
- fakeDirent('/out/api/resources/users/methods/create', 'index.html'),
87
- ]);
88
-
89
- const result = await getProsePages({ outputBasePath: '/out' });
90
-
91
- expect(result).toEqual([join('/out', 'index.html'), join('/out/guides', 'intro.html')]);
92
- });
93
-
94
- it('excludes non-HTML files', async () => {
95
- stubReaddir([
96
- fakeDirent('/out', 'index.html'),
97
- fakeDirent('/out', 'style.css'),
98
- fakeDirent('/out', 'app.js'),
99
- ]);
100
-
101
- const result = await getProsePages({ outputBasePath: '/out' });
102
-
103
- expect(result).toEqual([join('/out', 'index.html')]);
104
- });
105
-
106
- it('excludes directories', async () => {
107
- stubReaddir([fakeDirent('/out', 'index.html'), fakeDirent('/out', 'guides', false)]);
108
-
109
- const result = await getProsePages({ outputBasePath: '/out' });
110
-
111
- expect(result).toEqual([join('/out', 'index.html')]);
112
- });
113
-
114
- it('returns empty when all HTML files are in the manifest', async () => {
115
- stubManifest(['index.html', 'resources/users/index.html']);
116
- stubReaddir([fakeDirent('/out', 'index.html'), fakeDirent('/out/resources/users', 'index.html')]);
117
-
118
- const result = await getProsePages({ outputBasePath: '/out' });
119
-
120
- expect(result).toEqual([]);
121
- });
122
-
123
- it('returns empty when output has no HTML files', async () => {
124
- stubReaddir([fakeDirent('/out', 'style.css')]);
125
-
126
- const result = await getProsePages({ outputBasePath: '/out' });
127
-
128
- expect(result).toEqual([]);
129
- });
130
- });