Skip to content

Commit 3cb21bd

Browse files
feat: build llms.txt on build
1 parent 6b9f987 commit 3cb21bd

File tree

2 files changed

+22
-10832
lines changed

2 files changed

+22
-10832
lines changed

src/routes/docs/llms.txt/+server.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
1-
import { readFileSync } from 'fs';
2-
import { fileURLToPath } from 'url';
3-
import { dirname, join } from 'path';
1+
import { resolveRoute } from '$app/paths';
42
import type { RequestHandler } from '@sveltejs/kit';
53

6-
const BASE_DIR = dirname(fileURLToPath(import.meta.url));
4+
export const prerender = true;
75

8-
export const GET: RequestHandler = () => {
6+
const markdocFiles = import.meta.glob('$routes/docs/**/+page.markdoc', {
7+
query: '?raw',
8+
import: 'default',
9+
eager: true
10+
});
11+
12+
export const GET: RequestHandler = ({ request }) => {
913
try {
10-
const contentPath = join(BASE_DIR, 'content.txt');
11-
const llmsContent = readFileSync(contentPath, 'utf-8');
14+
const content = Object.keys(markdocFiles).reduce((acc, path) => {
15+
const content = markdocFiles[path] as string;
16+
17+
const route = path.replace(/^\/src\/routes/, '').replace(/\/\+page\.markdoc$/, '');
18+
const url = new URL(resolveRoute(route, {}), request.url);
19+
20+
return acc + `\n# ${url}\n\n${content}\n\n---\n\n`;
21+
}, '# Appwrite Documentation\n\n');
1222

13-
return new Response(llmsContent, {
23+
return new Response(content, {
1424
headers: {
15-
'Content-Type': 'text/plain; charset=utf-8'
25+
'Content-Type': 'text/plain; charset=utf-8',
26+
'Cache-Control': 'public, max-age=3600'
1627
}
1728
});
1829
} catch (error) {
19-
console.error('Error reading llms content:', error);
20-
return new Response('Content not found', {
30+
console.error('Error reading markdoc files:', error);
31+
return new Response('Error processing documentation files', {
2132
status: 500,
2233
headers: {
2334
'Content-Type': 'text/plain'

0 commit comments

Comments
 (0)