-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Expand file tree
/
Copy pathllms.txt.tsx
More file actions
85 lines (70 loc) · 1.93 KB
/
llms.txt.tsx
File metadata and controls
85 lines (70 loc) · 1.93 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type {GetServerSideProps} from 'next';
import {siteConfig} from '../siteConfig';
import sidebarLearn from '../sidebarLearn.json';
import sidebarReference from '../sidebarReference.json';
import sidebarBlog from '../sidebarBlog.json';
interface RouteItem {
title?: string;
path?: string;
routes?: RouteItem[];
}
interface Sidebar {
title: string;
routes: RouteItem[];
}
function extractRoutes(
routes: RouteItem[],
baseUrl: string
): {title: string; url: string}[] {
const result: {title: string; url: string}[] = [];
for (const route of routes) {
if (route.title && route.path) {
result.push({
title: route.title,
url: `${baseUrl}${route.path}.md`,
});
}
if (route.routes) {
result.push(...extractRoutes(route.routes, baseUrl));
}
}
return result;
}
const sidebars: Sidebar[] = [
sidebarLearn as Sidebar,
sidebarReference as Sidebar,
sidebarBlog as Sidebar,
];
export const getServerSideProps: GetServerSideProps = async ({res}) => {
const subdomain =
siteConfig.languageCode === 'en' ? '' : siteConfig.languageCode + '.';
const baseUrl = 'https://' + subdomain + 'react.dev';
const lines = [
'# React Documentation',
'',
'> The library for web and native user interfaces.',
];
for (const sidebar of sidebars) {
lines.push('');
lines.push(`## ${sidebar.title}`);
lines.push('');
const routes = extractRoutes(sidebar.routes, baseUrl);
for (const route of routes) {
lines.push(`- [${route.title}](${route.url})`);
}
}
const content = lines.join('\n');
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
res.write(content);
res.end();
return {props: {}};
};
export default function LlmsTxt() {
return null;
}