-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathroute.ts
More file actions
66 lines (56 loc) · 2.4 KB
/
route.ts
File metadata and controls
66 lines (56 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { type NextRequest, NextResponse } from 'next/server';
import { docsVersions, latestVersion } from '@repo/utils';
import { getAllTrees } from '../../lib/get-all-trees';
import { getFlatTree } from '../../lib/get-flat-tree';
import { resolveVersionFromSlug } from '../../lib/resolve-doc-for-llm';
import { getLlmsBannerLines } from '../../lib/get-llms-banner-lines';
export const dynamic = 'force-dynamic';
const baseUrl = 'https://storybook.js.org';
export function GET(request: NextRequest) {
const versionSlug = request.nextUrl.searchParams.get('version') ?? undefined;
const versionId = resolveVersionFromSlug(versionSlug);
const activeVersion =
docsVersions.find((v) => v.id === versionId) ?? latestVersion;
const listOfTrees = getAllTrees();
const tree = listOfTrees.find((t) => t.name === versionId);
const flatTree = tree?.children ? getFlatTree({ tree: tree.children }) : [];
const lines = [...getLlmsBannerLines({ version: activeVersion })];
for (const version of docsVersions) {
if (version.id === latestVersion.id) continue;
const slug = version.inSlug ?? version.id;
lines.push(`- \`/docs/${slug}/get-started.md\` — ${version.label}`);
}
lines.push('');
lines.push('Full documentation dump for older versions:');
for (const version of docsVersions) {
if (version.id === latestVersion.id) continue;
const slug = version.inSlug ?? version.id;
lines.push(`- \`/llms-full.txt?version=${slug}\` — ${version.label}`);
}
lines.push('');
lines.push('## Docs Pages');
lines.push('');
for (const node of flatTree) {
const indent = node.level > 1 ? ' '.repeat(node.level - 1) : '';
lines.push(`${indent}- ${node.slug}`);
}
lines.push('');
lines.push('## Community & Resources');
lines.push('');
lines.push(`- [Blog](${baseUrl}/blog): Storybook blog`);
lines.push(`- [Tutorials](${baseUrl}/tutorials): Step-by-step tutorials`);
lines.push(`- [Recipes](${baseUrl}/recipes): Integration recipes`);
lines.push(`- [Addons](${baseUrl}/addons): Addon catalog`);
lines.push(
`- [GitHub](https://github.com/storybookjs/storybook): Source code`,
);
lines.push(`- [Discord](https://discord.gg/storybook): Community chat`);
lines.push('');
return new NextResponse(lines.join('\n'), {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600',
'CDN-Cache-Control': 'no-store',
},
});
}