diff --git a/apps/svelte.dev/src/lib/components/PageControls.svelte b/apps/svelte.dev/src/lib/components/PageControls.svelte index df5f7c5624..ec792c5eb0 100644 --- a/apps/svelte.dev/src/lib/components/PageControls.svelte +++ b/apps/svelte.dev/src/lib/components/PageControls.svelte @@ -1,8 +1,10 @@

Edit this page on GitHub + {#if llms} + + llms.txt + + {/if}

@@ -44,9 +51,13 @@ position: relative; margin: 6rem 0 2rem 0; font: var(--sk-font-ui-small); + display: flex; a { text-decoration: none; + &:first-of-type { + margin-right: 5rem; + } } :global(svg) { diff --git a/apps/svelte.dev/src/lib/server/llms.ts b/apps/svelte.dev/src/lib/server/llms.ts index 3008cff916..4892c2728f 100644 --- a/apps/svelte.dev/src/lib/server/llms.ts +++ b/apps/svelte.dev/src/lib/server/llms.ts @@ -5,7 +5,7 @@ import { index } from './content'; interface GenerateLlmContentOptions { ignore?: string[]; minimize?: Partial; - sections: Section[]; + topics: Topic[]; } interface MinimizeOptions { @@ -17,7 +17,7 @@ interface MinimizeOptions { normalize_whitespace: boolean; } -interface Section { +interface Topic { slug: string; title: string; } @@ -34,13 +34,13 @@ const defaults: MinimizeOptions = { export function generate_llm_content(options: GenerateLlmContentOptions): string { let content = ''; - for (const section of options.sections) { - if (options.sections.length > 1) { - content += `# Start of ${section.title} documentation\n\n`; + for (const topic of options.topics) { + if (options.topics.length > 1) { + content += `# Start of ${topic.title} documentation\n\n`; } for (const [path, document] of Object.entries(index)) { - if (!path.startsWith(`docs/${section.slug}`)) continue; + if (!path.startsWith(`docs/${topic.slug}`)) continue; if (options.ignore?.some((pattern) => minimatch(path, pattern))) { if (dev) console.log(`❌ Ignored by pattern: ${path}`); @@ -61,14 +61,14 @@ export function generate_llm_content(options: GenerateLlmContentOptions): string return content; } -export const sections: Section[] = [ +export const topics: Topic[] = [ { slug: 'svelte', title: 'Svelte' }, { slug: 'kit', title: 'SvelteKit' }, { slug: 'cli', title: 'the Svelte CLI' } ]; -export function get_documentation_title(section: Section): string { - return `This is the developer documentation for ${section.title}.`; +export function get_documentation_title(topic: Topic): string { + return `This is the developer documentation for ${topic.title}.`; } function minimize_content(content: string, options?: Partial): string { diff --git a/apps/svelte.dev/src/routes/docs/[topic]/[...path]/+page.svelte b/apps/svelte.dev/src/routes/docs/[topic]/[...path]/+page.svelte index 664faf8e04..e3d566d732 100644 --- a/apps/svelte.dev/src/routes/docs/[topic]/[...path]/+page.svelte +++ b/apps/svelte.dev/src/routes/docs/[topic]/[...path]/+page.svelte @@ -83,6 +83,7 @@
{ - const [topic, ...rest] = section.slug.split('/'); - return { topic, path: rest.join('/') }; + return topics.map((topic) => { + return { topic: topic.slug, path: '' }; }); } export function GET({ params }) { - const pkg = params.path ? `${params.topic}/${params.path}` : params.topic; + if (params.path) { + const page = docs.pages[`docs/${params.topic}/${params.path}`]; - const section = sections.find((s) => s.slug === pkg); - - if (!section) { - error(404, 'Not Found'); - } + if (!page) { + error(404, 'Not Found'); + } - const prefix = `${get_documentation_title(section)}`; - const content = `${prefix}\n\n${generate_llm_content({ sections: [section] })}`; + return new Response(page.body, { + status: 200, + headers: { + 'Content-Type': 'text/plain; charset=utf-8', + 'Cache-Control': 'public, max-age=3600' + } + }); + } else { + const topic = topics.find((s) => s.slug === params.topic); - return new Response(content, { - status: 200, - headers: { - 'Content-Type': 'text/plain; charset=utf-8', - 'Cache-Control': 'public, max-age=3600' + if (!topic) { + error(404, 'Not Found'); } - }); + + const prefix = `${get_documentation_title(topic)}`; + const content = `${prefix}\n\n${generate_llm_content({ topics: [topic] })}`; + + return new Response(content, { + status: 200, + headers: { + 'Content-Type': 'text/plain; charset=utf-8', + 'Cache-Control': 'public, max-age=3600' + } + }); + } } diff --git a/apps/svelte.dev/src/routes/llms-full.txt/+server.ts b/apps/svelte.dev/src/routes/llms-full.txt/+server.ts index 18f2518797..180b9d4dae 100644 --- a/apps/svelte.dev/src/routes/llms-full.txt/+server.ts +++ b/apps/svelte.dev/src/routes/llms-full.txt/+server.ts @@ -1,9 +1,9 @@ -import { generate_llm_content, sections } from '$lib/server/llms'; +import { generate_llm_content, topics } from '$lib/server/llms'; export const prerender = true; export function GET() { - const content = `This is the full developer documentation for Svelte and SvelteKit.\n\n${generate_llm_content({ sections })}`; + const content = `This is the full developer documentation for Svelte and SvelteKit.\n\n${generate_llm_content({ topics })}`; return new Response(content, { status: 200, diff --git a/apps/svelte.dev/src/routes/llms-medium.txt/+server.ts b/apps/svelte.dev/src/routes/llms-medium.txt/+server.ts index 63eb51f77e..12281067e3 100644 --- a/apps/svelte.dev/src/routes/llms-medium.txt/+server.ts +++ b/apps/svelte.dev/src/routes/llms-medium.txt/+server.ts @@ -1,8 +1,8 @@ -import { generate_llm_content, sections } from '$lib/server/llms'; +import { generate_llm_content, topics } from '$lib/server/llms'; export function GET() { const main_content = generate_llm_content({ - sections, + topics, ignore: [ // Svelte ignores 'docs/svelte/legacy/**/*', diff --git a/apps/svelte.dev/src/routes/llms.txt/+server.ts b/apps/svelte.dev/src/routes/llms.txt/+server.ts index 9a961557c2..59b4f2bad2 100644 --- a/apps/svelte.dev/src/routes/llms.txt/+server.ts +++ b/apps/svelte.dev/src/routes/llms.txt/+server.ts @@ -1,4 +1,4 @@ -import { get_documentation_title, sections } from '$lib/server/llms'; +import { get_documentation_title, topics } from '$lib/server/llms'; import template from './template.md?raw'; const DOMAIN = `https://svelte.dev`; @@ -6,9 +6,9 @@ const DOMAIN = `https://svelte.dev`; export const prerender = true; export function GET() { - const package_docs = sections.map( - (section) => - `- [${section.title} documentation](${DOMAIN}/docs/${section.slug}/llms.txt): ${get_documentation_title(section)}` + const package_docs = topics.map( + (topic) => + `- [${topic.title} documentation](${DOMAIN}/docs/${topic.slug}/llms.txt): ${get_documentation_title(topic)}` ); const content = template.replace('%PACKAGE_DOCS%', package_docs.join('\n'));