|
1 | 1 | import { error } from '@sveltejs/kit'; |
2 | | -import { generate_llm_content, get_documentation_title, sections } from '$lib/server/llms'; |
| 2 | +import { docs } from '$lib/server/content.js'; |
| 3 | +import { generate_llm_content, get_documentation_title, topics } from '$lib/server/llms'; |
3 | 4 |
|
4 | 5 | export const prerender = true; |
5 | 6 |
|
6 | 7 | export function entries() { |
7 | | - return sections.map((section) => { |
8 | | - const [topic, ...rest] = section.slug.split('/'); |
9 | | - return { topic, path: rest.join('/') }; |
| 8 | + return topics.map((topic) => { |
| 9 | + return { topic: topic.slug, path: '' }; |
10 | 10 | }); |
11 | 11 | } |
12 | 12 |
|
13 | 13 | export function GET({ params }) { |
14 | | - const pkg = params.path ? `${params.topic}/${params.path}` : params.topic; |
| 14 | + if (params.path) { |
| 15 | + const page = docs.pages[`docs/${params.topic}/${params.path}`]; |
15 | 16 |
|
16 | | - const section = sections.find((s) => s.slug === pkg); |
17 | | - |
18 | | - if (!section) { |
19 | | - error(404, 'Not Found'); |
20 | | - } |
| 17 | + if (!page) { |
| 18 | + error(404, 'Not Found'); |
| 19 | + } |
21 | 20 |
|
22 | | - const prefix = `<SYSTEM>${get_documentation_title(section)}</SYSTEM>`; |
23 | | - const content = `${prefix}\n\n${generate_llm_content({ sections: [section] })}`; |
| 21 | + return new Response(page.body, { |
| 22 | + status: 200, |
| 23 | + headers: { |
| 24 | + 'Content-Type': 'text/plain; charset=utf-8', |
| 25 | + 'Cache-Control': 'public, max-age=3600' |
| 26 | + } |
| 27 | + }); |
| 28 | + } else { |
| 29 | + const topic = topics.find((s) => s.slug === params.topic); |
24 | 30 |
|
25 | | - return new Response(content, { |
26 | | - status: 200, |
27 | | - headers: { |
28 | | - 'Content-Type': 'text/plain; charset=utf-8', |
29 | | - 'Cache-Control': 'public, max-age=3600' |
| 31 | + if (!topic) { |
| 32 | + error(404, 'Not Found'); |
30 | 33 | } |
31 | | - }); |
| 34 | + |
| 35 | + const prefix = `<SYSTEM>${get_documentation_title(topic)}</SYSTEM>`; |
| 36 | + const content = `${prefix}\n\n${generate_llm_content({ topics: [topic] })}`; |
| 37 | + |
| 38 | + return new Response(content, { |
| 39 | + status: 200, |
| 40 | + headers: { |
| 41 | + 'Content-Type': 'text/plain; charset=utf-8', |
| 42 | + 'Cache-Control': 'public, max-age=3600' |
| 43 | + } |
| 44 | + }); |
| 45 | + } |
32 | 46 | } |
0 commit comments