nuxt-ai-ready 3.6.1 → 3.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-skills-config-CmZq9uWW.mjs +18 -0
- package/dist/agent-skills-zGLgFB6H.mjs +468 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +656 -570
- package/dist/devtools/pages/ai-ready/debug.vue +9 -3
- package/dist/devtools/pages/ai-ready/index.vue +3 -1
- package/dist/devtools/pages/ai-ready/llms-txt.vue +15 -4
- package/dist/devtools/pages/ai-ready.vue +28 -4
- package/dist/module.d.mts +106 -112
- package/dist/module.json +3 -3
- package/dist/module.mjs +2732 -26
- package/dist/package-metadata-B1darl8W.mjs +28 -0
- package/dist/prerender-QMv07W4h.mjs +650 -0
- package/dist/runtime/app/composables/webmcp.js +90 -97
- package/dist/runtime/app/plugins/md-alternate.server.js +29 -26
- package/dist/runtime/app/plugins/md-hints.prerender.js +13 -15
- package/dist/runtime/app/plugins/webmcp.client.js +49 -53
- package/dist/runtime/app/webmcp-config.js +2 -2
- package/dist/runtime/cache-control.js +16 -10
- package/dist/runtime/i18n-url.js +6 -6
- package/dist/runtime/index.js +4 -12
- package/dist/runtime/llms-txt-directive.js +20 -13
- package/dist/runtime/llms-txt-files.js +188 -187
- package/dist/runtime/llms-txt-format.js +54 -55
- package/dist/runtime/llms-txt-i18n.js +22 -19
- package/dist/runtime/llms-txt-utils.js +140 -95
- package/dist/runtime/markdown-links.js +45 -39
- package/dist/runtime/markdown-path.js +29 -9
- package/dist/runtime/markdown-text.js +2 -1
- package/dist/runtime/mcp.js +5 -1
- package/dist/runtime/route-path.js +14 -8
- package/dist/runtime/server/db/drizzle/client.js +71 -75
- package/dist/runtime/server/db/drizzle/index.js +16 -28
- package/dist/runtime/server/db/drizzle/providers/bun.d.ts +2 -1
- package/dist/runtime/server/db/drizzle/providers/bun.js +10 -7
- package/dist/runtime/server/db/drizzle/providers/d1.js +16 -13
- package/dist/runtime/server/db/drizzle/providers/dbPath.js +60 -37
- package/dist/runtime/server/db/drizzle/providers/libsql.js +23 -11
- package/dist/runtime/server/db/drizzle/providers/neon.js +13 -10
- package/dist/runtime/server/db/drizzle/providers/node-sqlite.js +10 -7
- package/dist/runtime/server/db/drizzle/providers/postgres.js +13 -10
- package/dist/runtime/server/db/drizzle/queries.js +633 -532
- package/dist/runtime/server/db/drizzle/raw.js +200 -176
- package/dist/runtime/server/db/index.js +3 -0
- package/dist/runtime/server/db/queries.js +816 -607
- package/dist/runtime/server/db/schema/postgres.js +56 -50
- package/dist/runtime/server/db/schema/sqlite.js +56 -50
- package/dist/runtime/server/db/schema-sql.js +35 -38
- package/dist/runtime/server/db/seed.js +60 -45
- package/dist/runtime/server/db/shared.js +300 -213
- package/dist/runtime/server/index.js +1 -17
- package/dist/runtime/server/mcp/cache-key.js +5 -1
- package/dist/runtime/server/mcp/resources/pages.js +32 -33
- package/dist/runtime/server/mcp/tools/get-page-markdown.js +41 -27
- package/dist/runtime/server/mcp/tools/list-pages.js +40 -34
- package/dist/runtime/server/mcp/tools/search-pages.js +24 -16
- package/dist/runtime/server/middleware/markdown.d.ts +1 -1
- package/dist/runtime/server/middleware/markdown.js +15 -13
- package/dist/runtime/server/middleware/markdown.prerender.d.ts +1 -1
- package/dist/runtime/server/middleware/markdown.prerender.js +135 -119
- package/dist/runtime/server/middleware/render-markdown.d.ts +1 -1
- package/dist/runtime/server/middleware/render-markdown.js +164 -144
- package/dist/runtime/server/plugins/ai-terms.d.ts +1 -1
- package/dist/runtime/server/plugins/ai-terms.js +4 -8
- package/dist/runtime/server/plugins/content-signal-capture-nitro3.prerender.d.ts +1 -1
- package/dist/runtime/server/plugins/content-signal-capture-nitro3.prerender.js +7 -8
- package/dist/runtime/server/plugins/content-signal-capture.prerender.d.ts +1 -1
- package/dist/runtime/server/plugins/content-signal-capture.prerender.js +7 -7
- package/dist/runtime/server/plugins/db-lifecycle-nitro3.d.ts +1 -1
- package/dist/runtime/server/plugins/db-lifecycle-nitro3.js +13 -14
- package/dist/runtime/server/plugins/db-lifecycle.js +13 -11
- package/dist/runtime/server/plugins/html-capture.prerender.js +6 -6
- package/dist/runtime/server/plugins/link-header-nitro3.d.ts +1 -1
- package/dist/runtime/server/plugins/link-header-nitro3.js +23 -13
- package/dist/runtime/server/plugins/link-header.d.ts +1 -1
- package/dist/runtime/server/plugins/link-header.js +30 -30
- package/dist/runtime/server/plugins/llms-txt-directive-html.d.ts +1 -1
- package/dist/runtime/server/plugins/llms-txt-directive-html.js +4 -3
- package/dist/runtime/server/plugins/markdown-negotiation.d.ts +1 -1
- package/dist/runtime/server/plugins/markdown-negotiation.js +64 -45
- package/dist/runtime/server/plugins/sitemap-seeder.js +144 -112
- package/dist/runtime/server/routes/__ai-ready/cron.get.d.ts +1 -1
- package/dist/runtime/server/routes/__ai-ready/cron.get.js +17 -11
- package/dist/runtime/server/routes/__ai-ready/devtools.get.d.ts +1 -1
- package/dist/runtime/server/routes/__ai-ready/devtools.get.js +60 -45
- package/dist/runtime/server/routes/__ai-ready/pages.get.d.ts +36 -1
- package/dist/runtime/server/routes/__ai-ready/pages.get.js +44 -40
- package/dist/runtime/server/routes/__ai-ready/poll.post.d.ts +15 -1
- package/dist/runtime/server/routes/__ai-ready/poll.post.js +30 -30
- package/dist/runtime/server/routes/__ai-ready/prune.post.d.ts +13 -1
- package/dist/runtime/server/routes/__ai-ready/prune.post.js +29 -15
- package/dist/runtime/server/routes/__ai-ready/reindex.post.d.ts +22 -1
- package/dist/runtime/server/routes/__ai-ready/reindex.post.js +31 -21
- package/dist/runtime/server/routes/__ai-ready/restore.post.d.ts +4 -1
- package/dist/runtime/server/routes/__ai-ready/restore.post.js +28 -22
- package/dist/runtime/server/routes/__ai-ready/status.get.d.ts +1 -1
- package/dist/runtime/server/routes/__ai-ready/status.get.js +52 -53
- package/dist/runtime/server/routes/__ai-ready-debug.get.d.ts +83 -1
- package/dist/runtime/server/routes/__ai-ready-debug.get.js +209 -189
- package/dist/runtime/server/routes/agent-skills-artifact.d.ts +1 -1
- package/dist/runtime/server/routes/agent-skills-artifact.js +16 -14
- package/dist/runtime/server/routes/agent-skills-index.d.ts +1 -1
- package/dist/runtime/server/routes/agent-skills-index.js +8 -6
- package/dist/runtime/server/routes/ai-catalog.js +19 -19
- package/dist/runtime/server/routes/ai-terms.js +23 -19
- package/dist/runtime/server/routes/api-catalog.js +23 -23
- package/dist/runtime/server/routes/llms-full.txt.get.d.ts +1 -1
- package/dist/runtime/server/routes/llms-full.txt.get.js +42 -41
- package/dist/runtime/server/routes/llms.txt.get.d.ts +1 -1
- package/dist/runtime/server/routes/llms.txt.get.js +38 -33
- package/dist/runtime/server/routes/mcp-server-card.js +19 -19
- package/dist/runtime/server/routes/sitemap.md.get.d.ts +1 -1
- package/dist/runtime/server/routes/sitemap.md.get.js +38 -39
- package/dist/runtime/server/tasks/ai-ready-cron.d.ts +1 -1
- package/dist/runtime/server/tasks/ai-ready-cron.js +17 -14
- package/dist/runtime/server/utils/auth.js +76 -53
- package/dist/runtime/server/utils/batchIndex.js +72 -60
- package/dist/runtime/server/utils/checkStale.js +181 -134
- package/dist/runtime/server/utils/cloudflare-prerendered.js +23 -20
- package/dist/runtime/server/utils/cloudflare.js +69 -51
- package/dist/runtime/server/utils/content-negotiation.js +30 -18
- package/dist/runtime/server/utils/content.js +4 -1
- package/dist/runtime/server/utils/context.js +30 -19
- package/dist/runtime/server/utils/cron-plan.js +6 -6
- package/dist/runtime/server/utils/discovery-response.js +5 -6
- package/dist/runtime/server/utils/fetch.js +2 -1
- package/dist/runtime/server/utils/frontmatter.js +44 -57
- package/dist/runtime/server/utils/i18n.js +3 -8
- package/dist/runtime/server/utils/indexPage.js +152 -113
- package/dist/runtime/server/utils/keywords.js +278 -277
- package/dist/runtime/server/utils/link-header.js +67 -56
- package/dist/runtime/server/utils/llms-full.js +39 -49
- package/dist/runtime/server/utils/markdown-redirect.js +26 -14
- package/dist/runtime/server/utils/markdown-request.js +62 -47
- package/dist/runtime/server/utils/negotiation-decision.d.ts +8 -0
- package/dist/runtime/server/utils/negotiation-decision.js +106 -34
- package/dist/runtime/server/utils/negotiation-response.d.ts +1 -1
- package/dist/runtime/server/utils/negotiation-response.js +195 -144
- package/dist/runtime/server/utils/page-updated-at.js +23 -15
- package/dist/runtime/server/utils/prerender-html.js +31 -17
- package/dist/runtime/server/utils/runCron.js +263 -192
- package/dist/runtime/server/utils/sitemap-crawl-state.js +57 -39
- package/dist/runtime/server/utils/sitemap-lastmod.js +16 -14
- package/dist/runtime/server/utils/sitemap-md.js +39 -50
- package/dist/runtime/server/utils/sitemap-routes.js +7 -7
- package/dist/runtime/server/utils/sitemap.js +459 -414
- package/dist/runtime/server/utils.js +141 -122
- package/dist/runtime/site-tool-catalog.js +39 -43
- package/dist/runtime/site-tool-config.js +1 -0
- package/dist/runtime/sync-secret.js +11 -11
- package/dist/runtime/types.js +1 -0
- package/dist/runtime/webmcp-site-tools.js +278 -250
- package/dist/runtime/webmcp.js +53 -42
- package/dist/static-headers-G7hFL3wE.mjs +328 -0
- package/dist/types.d.mts +1 -9
- package/package.json +18 -22
- package/skills/nuxt-ai-ready/SKILL.md +8 -2
- package/dist/chunks/agent-skills.mjs +0 -383
- package/dist/chunks/prerender.mjs +0 -683
- package/dist/shared/nuxt-ai-ready.Bzx0dNWj.mjs +0 -3034
- package/dist/shared/nuxt-ai-ready.DCd-1s1G.mjs +0 -29
|
@@ -2,195 +2,196 @@ import { formatLlmsTxtPageLink, normalizeLlmsTxtConfig } from "./llms-txt-format
|
|
|
2
2
|
const FILE_PATH = /^\/llms\/[a-z0-9][\w-]*\.txt$/i;
|
|
3
3
|
const SITEMAP_NAME = /^[a-z0-9][\w-]*$/i;
|
|
4
4
|
export function llmsTxtSectionPath(section) {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const name = Array.isArray(section.sitemap) ? section.sitemap[0] : section.sitemap;
|
|
6
|
+
return section.path || `/llms/${name}.txt`;
|
|
7
7
|
}
|
|
8
|
+
/** Parse the public configuration once, before Nitro registers routes. */
|
|
8
9
|
export function parseLlmsTxtConfig(input) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return invalid(`Duplicate llmsTxt section path: ${path}.`);
|
|
38
|
-
paths.add(path);
|
|
39
|
-
}
|
|
40
|
-
return { _tag: "Valid", config };
|
|
10
|
+
const invalid = (message) => ({
|
|
11
|
+
_tag: "Invalid",
|
|
12
|
+
message
|
|
13
|
+
});
|
|
14
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) return invalid("llmsTxt must be an object or false.");
|
|
15
|
+
const config = input;
|
|
16
|
+
if (config.pages !== undefined && config.pages !== false && config.pages !== "sitemap" && config.pages !== "all") return invalid("llmsTxt.pages must be sitemap, all, or false.");
|
|
17
|
+
if (config.maxLength !== undefined && (!Number.isSafeInteger(config.maxLength) || config.maxLength < 1024)) return invalid("llmsTxt.maxLength must be an integer of at least 1024.");
|
|
18
|
+
if (config.sitemaps !== undefined && (!Array.isArray(config.sitemaps) || config.sitemaps.some((name) => typeof name !== "string" || !SITEMAP_NAME.test(name)))) return invalid("llmsTxt.sitemaps must contain sitemap names.");
|
|
19
|
+
if (config.sections !== undefined && !Array.isArray(config.sections)) return invalid("llmsTxt.sections must be an array.");
|
|
20
|
+
const paths = new Set();
|
|
21
|
+
for (const section of config.sections || []) {
|
|
22
|
+
if (!section || typeof section !== "object" || typeof section.title !== "string") return invalid("Each llmsTxt section needs a title.");
|
|
23
|
+
if (section.sitemap === undefined) {
|
|
24
|
+
if (section.path !== undefined) return invalid("A section path requires a sitemap.");
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const names = Array.isArray(section.sitemap) ? section.sitemap : [section.sitemap];
|
|
28
|
+
if (!names.length || names.some((name) => typeof name !== "string" || !SITEMAP_NAME.test(name))) return invalid("Each section sitemap must contain a sitemap name.");
|
|
29
|
+
const path = llmsTxtSectionPath(section);
|
|
30
|
+
if (!FILE_PATH.test(path)) return invalid("A section path must use /llms/<name>.txt.");
|
|
31
|
+
if (paths.has(path)) return invalid(`Duplicate llmsTxt section path: ${path}.`);
|
|
32
|
+
paths.add(path);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
_tag: "Valid",
|
|
36
|
+
config
|
|
37
|
+
};
|
|
41
38
|
}
|
|
39
|
+
/** A bounded tree of file lists. Every page appears once; every file is reachable from the root. */
|
|
42
40
|
export function createLlmsTxtFiles(input) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
`;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
${
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
41
|
+
const files = new Map();
|
|
42
|
+
const maxLength = input.config.maxLength ?? 8e4;
|
|
43
|
+
const link = (title, path, description) => formatLlmsTxtPageLink({
|
|
44
|
+
pathname: path,
|
|
45
|
+
href: input.resolveUrl(path),
|
|
46
|
+
title,
|
|
47
|
+
description
|
|
48
|
+
});
|
|
49
|
+
const render = (header, title, lines) => `${header.trim()}\n\n## ${title.replace(/\s+/g, " ").trim()}\n\n${lines.join("\n")}\n`;
|
|
50
|
+
function tree(path, prefix, header, title, lines, level = 0) {
|
|
51
|
+
const body = render(header, title, lines);
|
|
52
|
+
if (body.length <= maxLength) {
|
|
53
|
+
files.set(path, body);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const overhead = render(header, title, []).length;
|
|
57
|
+
const chunks = [];
|
|
58
|
+
let chunk = [];
|
|
59
|
+
let length = overhead;
|
|
60
|
+
for (const line of lines) {
|
|
61
|
+
if (overhead + line.length + 1 > maxLength) throw new Error("An llms.txt entry exceeds llmsTxt.maxLength. Shorten the entry or increase the limit.");
|
|
62
|
+
if (length + line.length + 1 > maxLength) {
|
|
63
|
+
chunks.push(chunk);
|
|
64
|
+
chunk = [];
|
|
65
|
+
length = overhead;
|
|
66
|
+
}
|
|
67
|
+
chunk.push(line);
|
|
68
|
+
length += line.length + 1;
|
|
69
|
+
}
|
|
70
|
+
if (chunk.length) chunks.push(chunk);
|
|
71
|
+
const links = chunks.map((entries, index) => {
|
|
72
|
+
const child = `/llms/_${prefix}-${level}-${index + 1}.txt`;
|
|
73
|
+
files.set(child, render(header, title, entries));
|
|
74
|
+
return link(`${title} ${index + 1}`, child);
|
|
75
|
+
});
|
|
76
|
+
if (chunks.length >= lines.length && render(header, title, links).length >= body.length) throw new Error("llmsTxt.maxLength cannot fit an index. Increase the limit.");
|
|
77
|
+
tree(path, prefix, header, title, links, level + 1);
|
|
78
|
+
}
|
|
79
|
+
const sections = [];
|
|
80
|
+
const assigned = new Set();
|
|
81
|
+
for (const [index, section] of input.sections.entries()) {
|
|
82
|
+
if (!section.sitemap) {
|
|
83
|
+
sections.push(section);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const names = Array.isArray(section.sitemap) ? section.sitemap : [section.sitemap];
|
|
87
|
+
const pages = new Map();
|
|
88
|
+
for (const name of names) {
|
|
89
|
+
for (const page of input.sitemapPages.get(name) || []) {
|
|
90
|
+
// A page in several sitemaps belongs to the first configured section.
|
|
91
|
+
if (!assigned.has(page.pathname)) pages.set(page.pathname, page);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const entries = [...(section.links || []).map((entry) => formatLlmsTxtPageLink({
|
|
95
|
+
pathname: entry.href,
|
|
96
|
+
...entry
|
|
97
|
+
})), ...[...pages.values()].map(formatLlmsTxtPageLink)];
|
|
98
|
+
if (!entries.length) continue;
|
|
99
|
+
for (const pathname of pages.keys()) assigned.add(pathname);
|
|
100
|
+
const path = llmsTxtSectionPath(section);
|
|
101
|
+
const description = Array.isArray(section.description) ? section.description.join(" ") : section.description;
|
|
102
|
+
const preamble = normalizeLlmsTxtConfig({ notes: description });
|
|
103
|
+
tree(path, `section-${index + 1}`, `${input.header.trim()}\n\n${preamble}\n\n${link("llms.txt", "/llms.txt")}`, section.title, entries);
|
|
104
|
+
sections.push({
|
|
105
|
+
...section,
|
|
106
|
+
sitemap: undefined,
|
|
107
|
+
path: undefined,
|
|
108
|
+
links: [{
|
|
109
|
+
title: section.title,
|
|
110
|
+
href: input.resolveUrl(path),
|
|
111
|
+
description
|
|
112
|
+
}]
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const rootPreamble = `${input.header.trim()}\n\n${normalizeLlmsTxtConfig({ notes: input.config.notes })}${input.rootContent ? `\n\n${input.rootContent}` : ""}`;
|
|
116
|
+
const pageIndexSpace = input.pages.some((page) => !assigned.has(page.pathname)) ? render("", "Pages", [link("Pages", "/llms/_pages.txt")]).length : 1;
|
|
117
|
+
let rootHeader = `${input.header.trim()}\n\n${normalizeLlmsTxtConfig({
|
|
118
|
+
...input.config,
|
|
119
|
+
sections
|
|
120
|
+
})}${input.rootContent ? `\n\n${input.rootContent}` : ""}`;
|
|
121
|
+
if (rootHeader.length + pageIndexSpace > maxLength) {
|
|
122
|
+
const references = sections.flatMap((section, index) => {
|
|
123
|
+
const path = `/llms/_configured-${index + 1}.txt`;
|
|
124
|
+
if (!section.links?.length) {
|
|
125
|
+
const context = normalizeLlmsTxtConfig({ sections: [section] });
|
|
126
|
+
if (!context) return [];
|
|
127
|
+
const body = `${input.header.trim()}\n\n${context}\n\n${link("llms.txt", "/llms.txt")}\n`;
|
|
128
|
+
if (body.length > maxLength) throw new Error("An llms.txt entry exceeds llmsTxt.maxLength. Shorten the entry or increase the limit.");
|
|
129
|
+
files.set(path, body);
|
|
130
|
+
return [{
|
|
131
|
+
title: section.title,
|
|
132
|
+
links: [{
|
|
133
|
+
title: section.title,
|
|
134
|
+
href: input.resolveUrl(path)
|
|
135
|
+
}]
|
|
136
|
+
}];
|
|
137
|
+
}
|
|
138
|
+
const text = normalizeLlmsTxtConfig({ sections: [{
|
|
139
|
+
...section,
|
|
140
|
+
description: section.optional ? section.description : undefined
|
|
141
|
+
}] });
|
|
142
|
+
const lines = text.split("\n").slice(2);
|
|
143
|
+
const description = Array.isArray(section.description) ? section.description.join(" ") : section.description;
|
|
144
|
+
const preamble = section.optional ? "" : normalizeLlmsTxtConfig({ notes: description });
|
|
145
|
+
tree(path, `configured-${index + 1}`, `${input.header.trim()}\n\n${preamble}\n\n${link("llms.txt", "/llms.txt")}`, section.optional ? "Optional" : section.title, lines);
|
|
146
|
+
return [{
|
|
147
|
+
title: section.title,
|
|
148
|
+
optional: section.optional,
|
|
149
|
+
links: [{
|
|
150
|
+
title: section.title,
|
|
151
|
+
href: input.resolveUrl(path),
|
|
152
|
+
description
|
|
153
|
+
}]
|
|
154
|
+
}];
|
|
155
|
+
});
|
|
156
|
+
rootHeader = `${rootPreamble}\n\n${normalizeLlmsTxtConfig({ sections: references })}`;
|
|
157
|
+
if (rootHeader.length + pageIndexSpace > maxLength) {
|
|
158
|
+
const indexes = [];
|
|
159
|
+
for (const optional of [false, true]) {
|
|
160
|
+
const selected = references.filter((section) => Boolean(section.optional) === optional);
|
|
161
|
+
if (!selected.length) continue;
|
|
162
|
+
const title = optional ? "Optional" : "Sections";
|
|
163
|
+
const path = optional ? "/llms/_optional.txt" : "/llms/_sections.txt";
|
|
164
|
+
const text = normalizeLlmsTxtConfig({ sections: selected.map((section) => ({
|
|
165
|
+
...section,
|
|
166
|
+
optional: true
|
|
167
|
+
})) });
|
|
168
|
+
tree(path, optional ? "optional" : "sections", input.header, title, text.split("\n").slice(2));
|
|
169
|
+
indexes.push({
|
|
170
|
+
title,
|
|
171
|
+
optional,
|
|
172
|
+
links: [{
|
|
173
|
+
title,
|
|
174
|
+
href: input.resolveUrl(path)
|
|
175
|
+
}]
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
rootHeader = `${rootPreamble}\n\n${normalizeLlmsTxtConfig({ sections: indexes })}`;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const pages = input.pages.filter((page) => !assigned.has(page.pathname)).map(formatLlmsTxtPageLink);
|
|
182
|
+
if (!pages.length && rootHeader.length + 1 <= maxLength) {
|
|
183
|
+
files.set("/llms.txt", `${rootHeader.trim()}\n`);
|
|
184
|
+
} else {
|
|
185
|
+
// Child lists carry only the site header, not the root's custom sections.
|
|
186
|
+
const inline = render(rootHeader, "Pages", pages);
|
|
187
|
+
if (inline.length <= maxLength) {
|
|
188
|
+
files.set("/llms.txt", inline);
|
|
189
|
+
} else {
|
|
190
|
+
tree("/llms/_pages.txt", "pages", input.header, "Pages", pages);
|
|
191
|
+
const root = `${rootHeader.trim()}\n\n## Pages\n\n${link("Pages", "/llms/_pages.txt")}\n`;
|
|
192
|
+
if (root.length > maxLength) throw new Error("llms.txt sections exceed llmsTxt.maxLength. Shorten the sections or increase the limit.");
|
|
193
|
+
files.set("/llms.txt", root);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return files;
|
|
196
197
|
}
|
|
@@ -4,81 +4,80 @@ const RE_LINK_TITLE_BRACKET = /[[\]]/g;
|
|
|
4
4
|
const RE_LINK_HREF_UNSAFE = /[\s()]/g;
|
|
5
5
|
const RE_PREAMBLE_ATX_HEADING = /^( {0,3})(#{1,6})(?=\s)/gm;
|
|
6
6
|
function normalizeInlineText(value) {
|
|
7
|
-
|
|
7
|
+
return value.trim().replace(RE_INLINE_WHITESPACE, " ");
|
|
8
8
|
}
|
|
9
9
|
function normalizeLinkTitle(value) {
|
|
10
|
-
|
|
10
|
+
return escapeMarkdownHtml(normalizeInlineText(value)).replace(RE_LINK_TITLE_BRACKET, (bracket) => bracket === "[" ? "[" : "]");
|
|
11
11
|
}
|
|
12
12
|
function normalizeLinkHref(value) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return encodeURIComponent(character);
|
|
19
|
-
});
|
|
13
|
+
return value.trim().replace(RE_LINK_HREF_UNSAFE, (character) => {
|
|
14
|
+
if (character === "(") return "%28";
|
|
15
|
+
if (character === ")") return "%29";
|
|
16
|
+
return encodeURIComponent(character);
|
|
17
|
+
});
|
|
20
18
|
}
|
|
21
19
|
function normalizeDescriptions(value) {
|
|
22
|
-
|
|
20
|
+
return (Array.isArray(value) ? value : value ? [value] : []).filter((description) => description.trim()).map(normalizeInlineText);
|
|
23
21
|
}
|
|
24
22
|
function normalizePreambleBlocks(value) {
|
|
25
|
-
|
|
23
|
+
return (Array.isArray(value) ? value : value ? [value] : []).filter((block) => block.trim()).map((block) => block.trim().replace(RE_PREAMBLE_ATX_HEADING, "$1\\$2"));
|
|
26
24
|
}
|
|
27
25
|
function normalizeLink(link, descriptionPrefixes = []) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
const descriptions = [...descriptionPrefixes, link.description].filter((value) => Boolean(value?.trim())).map(normalizeInlineText);
|
|
27
|
+
const description = descriptions.join("; ");
|
|
28
|
+
return `- [${normalizeLinkTitle(link.title)}](${normalizeLinkHref(link.href)})${description ? `: ${description}` : ""}`;
|
|
31
29
|
}
|
|
32
30
|
function normalizeSection(section) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return parts.join("\n");
|
|
31
|
+
const parts = [`## ${escapeMarkdownHtml(normalizeInlineText(section.title))}`];
|
|
32
|
+
if (section.links?.length) parts.push("", ...section.links.map((link) => normalizeLink(link)));
|
|
33
|
+
return parts.join("\n");
|
|
37
34
|
}
|
|
38
35
|
function normalizePreamble(config) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
parts.push([`**${escapeMarkdownHtml(normalizeInlineText(section.title))}:**`, ...descriptions].join("\n\n"));
|
|
51
|
-
}
|
|
52
|
-
return parts;
|
|
36
|
+
const parts = [];
|
|
37
|
+
if (config.notes) {
|
|
38
|
+
const notes = normalizePreambleBlocks(config.notes);
|
|
39
|
+
if (notes.length) parts.push(["**Notes:**", ...notes].join("\n\n"));
|
|
40
|
+
}
|
|
41
|
+
for (const section of config.sections?.filter((section) => !section.optional) ?? []) {
|
|
42
|
+
if (!section.description) continue;
|
|
43
|
+
const descriptions = normalizePreambleBlocks(section.description);
|
|
44
|
+
if (descriptions.length) parts.push([`**${escapeMarkdownHtml(normalizeInlineText(section.title))}:**`, ...descriptions].join("\n\n"));
|
|
45
|
+
}
|
|
46
|
+
return parts;
|
|
53
47
|
}
|
|
54
48
|
function normalizeOptionalSections(sections) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
const links = sections.flatMap((section) => section.links?.map((link) => normalizeLink(link, [section.title, ...normalizeDescriptions(section.description)])) ?? []);
|
|
50
|
+
if (!links.length) return undefined;
|
|
51
|
+
return [
|
|
52
|
+
"## Optional",
|
|
53
|
+
"",
|
|
54
|
+
...links
|
|
55
|
+
].join("\n");
|
|
61
56
|
}
|
|
62
57
|
function normalizeRequiredSections(sections) {
|
|
63
|
-
|
|
58
|
+
return sections.filter((section) => section.links?.length).map(normalizeSection);
|
|
64
59
|
}
|
|
65
60
|
export function formatLlmsTxtPageLink(page) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
const description = page.description?.trim().replace(RE_INLINE_WHITESPACE, " ");
|
|
62
|
+
const normalizedTitle = page.title ? normalizeInlineText(page.title) : "";
|
|
63
|
+
const title = normalizedTitle && normalizedTitle !== page.pathname ? normalizedTitle : page.pathname;
|
|
64
|
+
const href = (page.href || page.pathname).trim();
|
|
65
|
+
const truncatedDescription = description ? `${description.substring(0, 160)}${description.length > 160 ? "..." : ""}` : undefined;
|
|
66
|
+
return normalizeLink({
|
|
67
|
+
title,
|
|
68
|
+
href,
|
|
69
|
+
description: truncatedDescription ? escapeMarkdownHtml(truncatedDescription) : undefined
|
|
70
|
+
});
|
|
72
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Normalize llms.txt structured configuration to the llmstxt.org Markdown format.
|
|
74
|
+
* Preamble prose must appear before the first H2; every H2 body is a file list.
|
|
75
|
+
*/
|
|
73
76
|
export function normalizeLlmsTxtConfig(config) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const optionalSection = normalizeOptionalSections(optional);
|
|
81
|
-
if (optionalSection)
|
|
82
|
-
parts.push(optionalSection);
|
|
83
|
-
return parts.join("\n\n");
|
|
77
|
+
const required = config.sections?.filter((section) => !section.optional) ?? [];
|
|
78
|
+
const optional = config.sections?.filter((section) => section.optional) ?? [];
|
|
79
|
+
const parts = [...normalizePreamble(config), ...normalizeRequiredSections(required)];
|
|
80
|
+
const optionalSection = normalizeOptionalSections(optional);
|
|
81
|
+
if (optionalSection) parts.push(optionalSection);
|
|
82
|
+
return parts.join("\n\n");
|
|
84
83
|
}
|
|
@@ -3,23 +3,26 @@ import { formatLlmsTxtPageLink } from "./llms-txt-format.js";
|
|
|
3
3
|
import { computeLocaleAlternates, localePath } from "./server/utils/i18n.js";
|
|
4
4
|
export { resolveLocaleFromRoute } from "./server/utils/i18n.js";
|
|
5
5
|
export function formatAvailableLanguagesSection(i18n, pageCounts, resolveHref = (pathname) => pathname, routeContext = {}) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
6
|
+
const lines = ["## Available Languages on Website", ""];
|
|
7
|
+
const rootAlternates = new Map(computeLocaleAlternates("/", i18n, routeContext).map((alternate) => [alternate.code, alternate]));
|
|
8
|
+
for (const locale of i18n.locales) {
|
|
9
|
+
const isDefault = locale.code === i18n.defaultLocale;
|
|
10
|
+
const alternate = rootAlternates.get(locale.code);
|
|
11
|
+
const prefix = alternate?.path ?? localePath("/", locale.code, i18n, routeContext);
|
|
12
|
+
const resolvedPath = resolveHref(prefix);
|
|
13
|
+
const href = alternate ? resolveLocaleAlternateUrl({
|
|
14
|
+
...alternate,
|
|
15
|
+
path: resolvedPath
|
|
16
|
+
}, (candidate) => candidate) : resolvedPath;
|
|
17
|
+
const count = pageCounts.get(locale.code) ?? 0;
|
|
18
|
+
const display = locale.nativeName ? `${locale.nativeName} (${locale.code})` : locale.name ? `${locale.name} (${locale.code})` : locale.code;
|
|
19
|
+
const suffix = isDefault ? "content included below" : "visit this language for content";
|
|
20
|
+
lines.push(formatLlmsTxtPageLink({
|
|
21
|
+
pathname: href,
|
|
22
|
+
title: display,
|
|
23
|
+
href,
|
|
24
|
+
description: `${count} pages; ${suffix}.`
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
return lines;
|
|
25
28
|
}
|