Skip to content

Commit 8b2544c

Browse files
committed
Filter llms.txt
1 parent 8612605 commit 8b2544c

File tree

4 files changed

+61
-8
lines changed

4 files changed

+61
-8
lines changed

apps/svelte.dev/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"lightningcss": "^1.25.1",
6969
"magic-string": "^0.30.11",
7070
"marked": "^14.1.2",
71+
"minimatch": "^10.0.1",
7172
"prettier": "^3.3.2",
7273
"prettier-plugin-svelte": "^3.2.4",
7374
"satori": "^0.10.13",

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { dev } from '$app/environment';
12
import { read } from '$app/server';
23
import type { Document } from '@sveltejs/site-kit';
34
import { create_index } from '@sveltejs/site-kit/server/content';
5+
import { minimatch } from 'minimatch';
46

57
const documents = import.meta.glob<string>('../../../content/**/*.md', {
68
eager: true,
@@ -272,6 +274,16 @@ function minimizeContent(content: string, options?: Partial<MinimizeOptions>): s
272274
return minimized;
273275
}
274276

277+
function shouldIncludeFile(filename: string, ignore: string[] = []): boolean {
278+
const shouldIgnore = ignore.some((pattern) => minimatch(filename, pattern));
279+
if (shouldIgnore) {
280+
if (dev) console.log(`❌ Ignored by pattern: ${filename}`);
281+
return false;
282+
}
283+
284+
return true;
285+
}
286+
275287
export function generateLlmContent(
276288
filteredDocs: Record<string, string>,
277289
type: Package,
@@ -295,13 +307,17 @@ export function generateLlmContent(
295307

296308
export function generateCombinedContent(
297309
documentsContent: Record<string, string>,
310+
ignore: string[] = [],
298311
minimizeOptions?: Partial<MinimizeOptions>
299312
): string {
300313
let content = '';
301314
let currentSection = '';
302315
const paths = sortPaths(Object.keys(documentsContent));
303316

304317
for (const path of paths) {
318+
// Skip files that match ignore patterns
319+
if (!shouldIncludeFile(path, ignore)) continue;
320+
305321
const docType = packages.find((pkg) => path.includes(`/docs/${pkg}/`));
306322
if (!docType) continue;
307323

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,39 @@ import { documentsContent, generateCombinedContent } from '$lib/server/content';
44
const PREFIX = 'This is the abridged developer documentation for Svelte and SvelteKit.';
55

66
export const GET: RequestHandler = async () => {
7-
const content = `${PREFIX}\n\n${generateCombinedContent(documentsContent, {
8-
removeLegacy: true,
9-
removeNoteBlocks: true,
10-
removeDetailsBlocks: true,
11-
removePlaygroundLinks: true,
12-
removePrettierIgnore: true,
13-
normalizeWhitespace: true
14-
})}`;
7+
const content = `${PREFIX}\n\n${generateCombinedContent(
8+
documentsContent,
9+
[
10+
// Svelte ignores
11+
'../../../content/docs/svelte/07-misc/04-custom-elements.md',
12+
'../../../content/docs/svelte/07-misc/06-v4-migration-guide.md',
13+
'../../../content/docs/svelte/07-misc/07-v5-migration-guide.md',
14+
'../../../content/docs/svelte/07-misc/99-faq.md',
15+
'../../../content/docs/svelte/07-misc/xx-reactivity-indepth.md',
16+
'../../../content/docs/svelte/98-reference/21-svelte-legacy.md',
17+
'../../../content/docs/svelte/99-legacy/**/*.md',
18+
'../../../content/docs/svelte/98-reference/30-runtime-errors.md',
19+
'../../../content/docs/svelte/98-reference/30-runtime-warnings.md',
20+
'../../../content/docs/svelte/98-reference/30-compiler-errors.md',
21+
'../../../content/docs/svelte/98-reference/30-compiler-warnings.md',
22+
'**/xx-*.md',
23+
24+
// SvelteKit ignores
25+
'../../../content/docs/kit/25-build-and-deploy/*adapter-*.md',
26+
'../../../content/docs/kit/25-build-and-deploy/99-writing-adapters.md',
27+
'../../../content/docs/kit/30-advanced/70-packaging.md',
28+
'../../../content/docs/kit/40-best-practices/05-performance.md',
29+
'../../../content/docs/kit/60-appendix/**/*.md'
30+
],
31+
{
32+
removeLegacy: true,
33+
removeNoteBlocks: true,
34+
removeDetailsBlocks: true,
35+
removePlaygroundLinks: true,
36+
removePrettierIgnore: true,
37+
normalizeWhitespace: true
38+
}
39+
)}`;
1540

1641
return new Response(content, {
1742
status: 200,

pnpm-lock.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)