Skip to content

Commit 4315f7a

Browse files
committed
wip
1 parent d494334 commit 4315f7a

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

apps/svelte.dev/src/lib/server/content.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,27 @@ export function generateLlmContent(filteredDocs: Record<string, string>, type: P
205205

206206
return content;
207207
}
208+
209+
export function generateCombinedContent(documentsContent: Record<string, string>): string {
210+
let content = '';
211+
let currentSection = '';
212+
const paths = sortPaths(Object.keys(documentsContent));
213+
214+
for (const path of paths) {
215+
const docType = packages.find((pkg) => path.includes(`/docs/${pkg}/`));
216+
if (!docType) continue;
217+
218+
const section = getDocumentationStartTitle(docType);
219+
if (section !== currentSection) {
220+
if (currentSection) content += '\n';
221+
content += `${section}\n\n`;
222+
currentSection = section;
223+
}
224+
225+
content += `## ${path.replace('../../../content/', '')}\n\n`;
226+
content += documentsContent[path];
227+
content += '\n';
228+
}
229+
230+
return content;
231+
}

apps/svelte.dev/src/routes/llms.txt/+server.ts

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,17 @@
11
import type { RequestHandler } from './$types';
2-
import { documentsContent, getDocumentationStartTitle, sortPaths } from '$lib/server/content';
2+
import { documentsContent, generateCombinedContent } from '$lib/server/content';
33

44
const PREFIX = 'This is the abridged developer documentation for Svelte and SvelteKit.';
55

66
export const GET: RequestHandler = async () => {
7-
let content = `${PREFIX}\n\n`;
8-
9-
const paths = sortPaths(Object.keys(documentsContent));
10-
11-
let currentSection = '';
12-
13-
for (const path of paths) {
14-
let section = '';
15-
if (path.includes('/docs/svelte/')) section = getDocumentationStartTitle('svelte');
16-
else if (path.includes('/docs/kit/')) section = getDocumentationStartTitle('kit');
17-
else if (path.includes('/docs/cli/')) section = getDocumentationStartTitle('cli');
18-
else continue;
19-
20-
if (section !== currentSection) {
21-
if (currentSection) content += '\n';
22-
content += `${section}\n\n`;
23-
currentSection = section;
24-
}
25-
26-
content += `## ${path.replace('../../../content/', '')}\n\n`;
27-
content += documentsContent[path];
28-
content += '\n';
29-
}
30-
31-
const headers: HeadersInit = {
32-
'Content-Type': 'text/plain; charset=utf-8',
33-
'Cache-Control': 'public, max-age=3600'
34-
};
7+
const content = `${PREFIX}\n\n${generateCombinedContent(documentsContent)}`;
358

369
return new Response(content, {
3710
status: 200,
38-
headers
11+
headers: {
12+
'Content-Type': 'text/plain; charset=utf-8',
13+
'Cache-Control': 'public, max-age=3600'
14+
}
3915
});
4016
};
4117

0 commit comments

Comments
 (0)