Skip to content

Commit 02dbf8d

Browse files
committed
clean up
1 parent 8b2544c commit 02dbf8d

File tree

4 files changed

+45
-48
lines changed

4 files changed

+45
-48
lines changed

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

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -284,54 +284,48 @@ function shouldIncludeFile(filename: string, ignore: string[] = []): boolean {
284284
return true;
285285
}
286286

287-
export function generateLlmContent(
288-
filteredDocs: Record<string, string>,
289-
type: Package,
290-
minimizeOptions?: Partial<MinimizeOptions>
291-
): string {
292-
let content = `<SYSTEM>${getDocumentationTitle(type)}</SYSTEM>\n\n`;
293-
294-
const paths = sortPaths(Object.keys(filteredDocs));
295-
296-
for (const path of paths) {
297-
content += `# ${path.replace('../../../content/', '')}\n\n`;
298-
const docContent = minimizeOptions
299-
? minimizeContent(filteredDocs[path], minimizeOptions)
300-
: filteredDocs[path];
301-
content += docContent;
302-
content += '\n';
303-
}
304-
305-
return content;
287+
interface GenerateContentOptions {
288+
prefix?: string;
289+
ignore?: string[];
290+
minimize?: Partial<MinimizeOptions>;
291+
package?: Package;
306292
}
307293

308-
export function generateCombinedContent(
309-
documentsContent: Record<string, string>,
310-
ignore: string[] = [],
311-
minimizeOptions?: Partial<MinimizeOptions>
294+
export function generateContent(
295+
docs: Record<string, string>,
296+
options: GenerateContentOptions = {}
312297
): string {
298+
const { prefix, ignore = [], minimize: minimizeOptions, package: pkg } = options;
299+
313300
let content = '';
301+
if (prefix) {
302+
content = `${prefix}\n\n`;
303+
}
304+
314305
let currentSection = '';
315-
const paths = sortPaths(Object.keys(documentsContent));
306+
const paths = sortPaths(Object.keys(docs));
316307

317308
for (const path of paths) {
318-
// Skip files that match ignore patterns
319309
if (!shouldIncludeFile(path, ignore)) continue;
320310

321-
const docType = packages.find((pkg) => path.includes(`/docs/${pkg}/`));
322-
if (!docType) continue;
323-
324-
const section = getDocumentationStartTitle(docType);
325-
if (section !== currentSection) {
326-
if (currentSection) content += '\n';
327-
content += `${section}\n\n`;
328-
currentSection = section;
311+
// If a specific package is provided, only include its docs
312+
if (pkg) {
313+
if (!path.includes(`/docs/${pkg}/`)) continue;
314+
} else {
315+
// For combined content, only include paths that match any package
316+
const docType = packages.find((p) => path.includes(`/docs/${p}/`));
317+
if (!docType) continue;
318+
319+
const section = getDocumentationStartTitle(docType);
320+
if (section !== currentSection) {
321+
if (currentSection) content += '\n';
322+
content += `${section}\n\n`;
323+
currentSection = section;
324+
}
329325
}
330326

331327
content += `## ${path.replace('../../../content/', '')}\n\n`;
332-
const docContent = minimizeOptions
333-
? minimizeContent(documentsContent[path], minimizeOptions)
334-
: documentsContent[path];
328+
const docContent = minimizeOptions ? minimizeContent(docs[path], minimizeOptions) : docs[path];
335329
content += docContent;
336330
content += '\n';
337331
}

apps/svelte.dev/src/routes/docs/[...path]/llms.txt/+server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { error } from '@sveltejs/kit';
44
import {
55
documentsContent,
66
filterDocsByPackage,
7-
generateLlmContent,
7+
generateContent,
8+
getDocumentationTitle,
89
packages,
910
type Package
1011
} from '$lib/server/content';
@@ -28,7 +29,8 @@ export const GET: RequestHandler = async ({ params }) => {
2829
error(404, 'No documentation found for this package');
2930
}
3031

31-
const content = generateLlmContent(filteredDocs, packageType as Package);
32+
const PREFIX = `<SYSTEM>${getDocumentationTitle(packageType)}</SYSTEM>`;
33+
const content = `${PREFIX}\n\n${generateContent(filteredDocs)}`;
3234

3335
return new Response(content, {
3436
status: 200,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import type { RequestHandler } from './$types';
2-
import { documentsContent, generateCombinedContent } from '$lib/server/content';
2+
import { documentsContent, generateContent } from '$lib/server/content';
33

4-
const PREFIX = 'This is the full developer documentation for Svelte and SvelteKit.';
4+
const PREFIX =
5+
'<SYSTEM>This is the full developer documentation for Svelte and SvelteKit.</SYSTEM>';
56

67
export const GET: RequestHandler = async () => {
7-
const content = `${PREFIX}\n\n${generateCombinedContent(documentsContent)}`;
8+
const content = `${PREFIX}\n\n${generateContent(documentsContent)}`;
89

910
return new Response(content, {
1011
status: 200,

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

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

4-
const PREFIX = 'This is the abridged developer documentation for Svelte and SvelteKit.';
4+
const PREFIX =
5+
'<SYSTEM>This is the abridged developer documentation for Svelte and SvelteKit.</SYSTEM>';
56

67
export const GET: RequestHandler = async () => {
7-
const content = `${PREFIX}\n\n${generateCombinedContent(
8-
documentsContent,
9-
[
8+
const content = `${PREFIX}\n\n${generateContent(documentsContent, {
9+
ignore: [
1010
// Svelte ignores
1111
'../../../content/docs/svelte/07-misc/04-custom-elements.md',
1212
'../../../content/docs/svelte/07-misc/06-v4-migration-guide.md',
@@ -28,15 +28,15 @@ export const GET: RequestHandler = async () => {
2828
'../../../content/docs/kit/40-best-practices/05-performance.md',
2929
'../../../content/docs/kit/60-appendix/**/*.md'
3030
],
31-
{
31+
minimize: {
3232
removeLegacy: true,
3333
removeNoteBlocks: true,
3434
removeDetailsBlocks: true,
3535
removePlaygroundLinks: true,
3636
removePrettierIgnore: true,
3737
normalizeWhitespace: true
3838
}
39-
)}`;
39+
})}`;
4040

4141
return new Response(content, {
4242
status: 200,

0 commit comments

Comments
 (0)