Skip to content

Commit 60a9372

Browse files
authored
Implement llms-full.txt (#5004)
* Implement llms-full * Add fields to package.json * Fix build
1 parent 3ac7bf0 commit 60a9372

File tree

6 files changed

+103
-19
lines changed

6 files changed

+103
-19
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as fs from "node:fs/promises";
2+
import { join } from "node:path";
3+
import { getLLMText } from "@/loaders/get-llm-text";
4+
import { source } from "@/loaders/source";
5+
6+
export const revalidate = false;
7+
8+
export async function GET() {
9+
const pages = source.getPages();
10+
11+
// Read meta.json to get the page order
12+
const metaPath = join(process.cwd(), "content", "meta.json");
13+
const meta = JSON.parse(await fs.readFile(metaPath, "utf-8"));
14+
15+
// Create a map of page URLs to their order in meta.json
16+
const pageOrder = new Map<string, number>();
17+
meta.pages.forEach((page: string, index: number) => {
18+
pageOrder.set(page, index);
19+
});
20+
21+
// Sort pages according to meta.json order
22+
const sortedPages = pages.sort((a, b) => {
23+
const aOrder = pageOrder.get(a.url) ?? Number.MAX_SAFE_INTEGER;
24+
const bOrder = pageOrder.get(b.url) ?? Number.MAX_SAFE_INTEGER;
25+
return aOrder - bOrder;
26+
});
27+
28+
// Generate content
29+
let txt = `# Zod
30+
31+
Zod is a TypeScript-first schema validation library with static type inference. This documentation provides comprehensive coverage of Zod 4's features, API, and usage patterns.
32+
33+
`;
34+
35+
// Process each page
36+
for (const page of sortedPages) {
37+
txt += await getLLMText(page);
38+
txt += "\n\n";
39+
}
40+
41+
return new Response(txt, {
42+
headers: { "Content-Type": "text/plain; charset=utf-8" },
43+
});
44+
}

‎packages/docs/content/v4/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Introducing Zod 4
2+
title: Release notes
33
description: "Zod 4 release notes and new features including performance improvements and breaking changes"
44
---
55

‎packages/docs/loaders/get-llm-text.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as fs from "node:fs/promises";
2+
import type { source } from "@/loaders/source";
3+
import type { InferPageType } from "fumadocs-core/source";
4+
import { remarkInclude } from "fumadocs-mdx/config";
5+
import matter from "gray-matter";
6+
import { remark } from "remark";
7+
import remarkGfm from "remark-gfm";
8+
import remarkMdx from "remark-mdx";
9+
import remarkStringify from "remark-stringify";
10+
11+
const processor = remark().use(remarkMdx).use(remarkInclude).use(remarkGfm).use(remarkStringify);
12+
13+
export async function getLLMText(page: InferPageType<typeof source>): Promise<string> {
14+
const filePath = page.data._file.absolutePath;
15+
const fileContent = await fs.readFile(filePath);
16+
const { content, data } = matter(fileContent.toString());
17+
18+
const processed = await processor.process({
19+
path: filePath,
20+
value: content,
21+
});
22+
23+
return `# ${page.data.title}
24+
25+
${processed}`;
26+
}

‎packages/docs/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@
1616
"fumadocs-core": "15.1.0",
1717
"fumadocs-mdx": "11.5.6",
1818
"fumadocs-ui": "15.1.0",
19+
"gray-matter": "^4.0.3",
1920
"lucide-react": "^0.483.0",
2021
"next": "15.2.2",
2122
"react": "^19.0.0",
22-
"react-dom": "^19.0.0"
23+
"react-dom": "^19.0.0",
24+
"remark": "^15.0.1",
25+
"remark-gfm": "^4.0.1",
26+
"remark-mdx": "^3.1.0",
27+
"remark-stringify": "^11.0.0"
2328
},
2429
"devDependencies": {
2530
"@tailwindcss/postcss": "^4.0.14",

‎packages/zod/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
"name": "zod",
33
"version": "4.0.11",
44
"type": "module",
5+
"license": "MIT",
56
"author": "Colin McDonnell <zod@colinhacks.com>",
67
"description": "TypeScript-first schema declaration and validation library with static type inference",
8+
"homepage": "https://zod.dev",
9+
"llms": "https://zod.dev/llms.txt",
10+
"llmsFull": "https://zod.dev/llms-full.txt",
11+
"mcpServer": "https://mcp.inkeep.com/zod/mcp",
12+
"funding": "https://github.com/sponsors/colinhacks",
13+
"sideEffects": false,
714
"files": [
815
"src",
916
"**/*.js",
@@ -13,19 +20,13 @@
1320
"**/*.d.mts",
1421
"**/*.d.cts"
1522
],
16-
"funding": "https://github.com/sponsors/colinhacks",
17-
"homepage": "https://zod.dev",
18-
"llms": "https://zod.dev/llms.txt",
19-
"mcp": "https://mcp.inkeep.com/zod/mcp",
2023
"keywords": [
2124
"typescript",
2225
"schema",
2326
"validation",
2427
"type",
2528
"inference"
2629
],
27-
"license": "MIT",
28-
"sideEffects": false,
2930
"main": "./index.cjs",
3031
"types": "./index.d.cts",
3132
"module": "./index.js",

‎pnpm-lock.yaml

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

0 commit comments

Comments
 (0)