|
1 | | -import { readFileSync } from 'fs'; |
2 | | -import { fileURLToPath } from 'url'; |
3 | | -import { dirname, join } from 'path'; |
| 1 | +import { resolveRoute } from '$app/paths'; |
4 | 2 | import type { RequestHandler } from '@sveltejs/kit'; |
5 | 3 |
|
6 | | -const BASE_DIR = dirname(fileURLToPath(import.meta.url)); |
| 4 | +export const prerender = true; |
7 | 5 |
|
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 }) => { |
9 | 13 | 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'); |
12 | 22 |
|
13 | | - return new Response(llmsContent, { |
| 23 | + return new Response(content, { |
14 | 24 | headers: { |
15 | | - 'Content-Type': 'text/plain; charset=utf-8' |
| 25 | + 'Content-Type': 'text/plain; charset=utf-8', |
| 26 | + 'Cache-Control': 'public, max-age=3600' |
16 | 27 | } |
17 | 28 | }); |
18 | 29 | } 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', { |
21 | 32 | status: 500, |
22 | 33 | headers: { |
23 | 34 | 'Content-Type': 'text/plain' |
|
0 commit comments