11import { type NextRequest , NextResponse } from 'next/server' ;
2- import { type DocsVersion , docsVersions , latestVersion } from '@repo/utils' ;
2+ import { docsVersions , latestVersion } from '@repo/utils' ;
33import { getAllTrees } from '../../lib/get-all-trees' ;
44import { getFlatTree } from '../../lib/get-flat-tree' ;
55import { resolveVersionFromSlug } from '../../lib/resolve-doc-for-llm' ;
6+ import { getLlmsBannerLines } from '../../lib/get-llm-banner-lines' ;
67
78export const dynamic = 'force-dynamic' ;
89
9- const baseUrl = 'https://storybook.js.org' ;
10-
11- export const getLlmsBannerLines = ( { version } : { version : DocsVersion } ) => [
12- '# Storybook' ,
13- '' ,
14- '> Storybook is a frontend workshop for building UI components and pages in isolation. It helps with UI development, testing, and documentation.' ,
15- '' ,
16- `Current version: ${ version . label } (${ version . id } )` ,
17- '' ,
18- '## Documentation' ,
19- '' ,
20- `- [Storybook Docs](${ baseUrl } /docs): Main documentation` ,
21- `- [Full Documentation (Markdown)](${ baseUrl } /llms-full.txt): Complete documentation in plain text for LLM consumption` ,
22- '' ,
23- '## Markdown Access' ,
24- '' ,
25- 'Append `.md` to any docs URL to get clean markdown with code examples:' ,
26- `- \`${ baseUrl } /docs/writing-stories/decorators.md\`` ,
27- `- \`${ baseUrl } /docs/9/writing-stories/decorators.md\` (Version 9)` ,
28- '' ,
29- '### Query Parameters' ,
30- '' ,
31- 'All markdown endpoints (`.md` URLs and `llms-full.txt`) support these query parameters:' ,
32- '- `renderer` - Framework filter for code snippets (default: `react`). Options: `react`, `vue`, `angular`, `svelte`, `web-components`, `solid`, `preact`, `html`, `ember`, `qwik`' ,
33- '- `language` - Language filter for code snippets (default: `ts`). Options: `ts`, `js`' ,
34- '- `codeOnly` - When `true`, returns only the code snippets without prose' ,
35- '' ,
36- 'Examples:' ,
37- '- `GET /docs/writing-stories/decorators.md?renderer=vue&language=ts`' ,
38- '- `GET /docs/writing-stories/decorators.md?codeOnly=true`' ,
39- '- `GET /llms-full.txt?renderer=angular&language=js`' ,
40- '' ,
41- '### Versioned Access' ,
42- '' ,
43- 'Prefix the path with a version slug for older versions:' ,
44- ] ;
45-
4610export function GET ( request : NextRequest ) {
11+ const baseUrl = `${ request . nextUrl . protocol } //${ request . nextUrl . host } ` ;
4712 const versionSlug = request . nextUrl . searchParams . get ( 'version' ) ?? undefined ;
4813 const versionId = resolveVersionFromSlug ( versionSlug ) ;
4914 const activeVersion =
@@ -53,7 +18,7 @@ export function GET(request: NextRequest) {
5318 const tree = listOfTrees . find ( ( t ) => t . name === versionId ) ;
5419 const flatTree = tree ?. children ? getFlatTree ( { tree : tree . children } ) : [ ] ;
5520
56- const lines = [ ...getLlmsBannerLines ( { version : activeVersion } ) ] ;
21+ const lines = [ ...getLlmsBannerLines ( { baseUrl , version : activeVersion } ) ] ;
5722
5823 for ( const version of docsVersions ) {
5924 if ( version . id === latestVersion . id ) continue ;
0 commit comments