@lukoweb/apitogo 0.1.15 → 0.1.17
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/cli/cli.js +425 -107
- package/package.json +1 -1
- package/src/vite/build.ts +237 -237
- package/src/vite/llms.ts +99 -99
- package/src/vite/prerender/prerender.ts +3 -1
package/src/vite/llms.ts
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
import { writeFile } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import colors from "picocolors";
|
|
4
|
-
import { joinUrl } from "../lib/util/joinUrl.js";
|
|
5
|
-
import type { MarkdownFileInfo } from "./plugin-markdown-export.js";
|
|
6
|
-
export async function generateLlmsTxtFiles({
|
|
7
|
-
markdownFileInfos,
|
|
8
|
-
outputUrls,
|
|
9
|
-
baseOutputDir,
|
|
10
|
-
basePath,
|
|
11
|
-
siteName,
|
|
12
|
-
llmsTxt,
|
|
13
|
-
llmsTxtFull,
|
|
14
|
-
redirectUrls,
|
|
15
|
-
}: {
|
|
16
|
-
markdownFileInfos: MarkdownFileInfo[];
|
|
17
|
-
basePath: string | undefined;
|
|
18
|
-
outputUrls: string[];
|
|
19
|
-
baseOutputDir: string;
|
|
20
|
-
siteName?: string;
|
|
21
|
-
llmsTxt?: boolean;
|
|
22
|
-
llmsTxtFull?: boolean;
|
|
23
|
-
redirectUrls: Set<string>;
|
|
24
|
-
}) {
|
|
25
|
-
const nonRedirectUrls = outputUrls.filter((url) => !redirectUrls.has(url));
|
|
26
|
-
|
|
27
|
-
const baseUrl = basePath ?? "";
|
|
28
|
-
const title = siteName ?? "Documentation";
|
|
29
|
-
|
|
30
|
-
const markdownMap = new Map(
|
|
31
|
-
markdownFileInfos.map((info) => [info.routePath, info]),
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
// Generate llms.txt
|
|
35
|
-
if (llmsTxt) {
|
|
36
|
-
const llmsTxtParts: string[] = [];
|
|
37
|
-
|
|
38
|
-
llmsTxtParts.push(`# ${title}\n`);
|
|
39
|
-
llmsTxtParts.push("> Documentation files for Large Language Models\n");
|
|
40
|
-
|
|
41
|
-
// Add documentation section with links to all pages (matching sitemap structure)
|
|
42
|
-
llmsTxtParts.push("## Documentation\n");
|
|
43
|
-
|
|
44
|
-
for (const url of nonRedirectUrls) {
|
|
45
|
-
// Skip error pages
|
|
46
|
-
if (/(400|404|500)$/.test(url)) continue;
|
|
47
|
-
|
|
48
|
-
const mdInfo = markdownMap.get(url);
|
|
49
|
-
|
|
50
|
-
// Only include pages that have markdown content
|
|
51
|
-
if (mdInfo) {
|
|
52
|
-
// If we have markdown for this page, link to the .md file
|
|
53
|
-
const mdUrl = joinUrl(baseUrl, `${url}.md`);
|
|
54
|
-
const linkTitle = mdInfo.title ?? url;
|
|
55
|
-
const description = mdInfo.description ? `: ${mdInfo.description}` : "";
|
|
56
|
-
llmsTxtParts.push(`- [${linkTitle}](${mdUrl})${description}`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const llmsTxt = llmsTxtParts.join("\n");
|
|
61
|
-
await writeFile(path.join(baseOutputDir, "llms.txt"), llmsTxt, "utf-8");
|
|
62
|
-
|
|
63
|
-
if (process.env.APITOGO_JSON_ONLY !== "1") {
|
|
64
|
-
// biome-ignore lint/suspicious/noConsole: Logging allowed here
|
|
65
|
-
console.log(colors.blue("✓ generated llms.txt"));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Generate llms-full.txt (full content of all markdown documents)
|
|
70
|
-
if (llmsTxtFull) {
|
|
71
|
-
const llmsFullParts: string[] = [];
|
|
72
|
-
|
|
73
|
-
llmsFullParts.push(`# ${title}\n`);
|
|
74
|
-
llmsFullParts.push("> Complete documentation for Large Language Models\n");
|
|
75
|
-
|
|
76
|
-
// Add each markdown document's full content
|
|
77
|
-
for (const info of markdownFileInfos) {
|
|
78
|
-
llmsFullParts.push(`\n---\n`);
|
|
79
|
-
llmsFullParts.push(`## Document: ${info.title ?? info.routePath}\n`);
|
|
80
|
-
if (info.description) {
|
|
81
|
-
llmsFullParts.push(`${info.description}\n`);
|
|
82
|
-
}
|
|
83
|
-
llmsFullParts.push(`URL: ${joinUrl(baseUrl, info.routePath)}\n`);
|
|
84
|
-
llmsFullParts.push(`\n${info.content}\n`);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const llmsFull = llmsFullParts.join("\n");
|
|
88
|
-
await writeFile(
|
|
89
|
-
path.join(baseOutputDir, "llms-full.txt"),
|
|
90
|
-
llmsFull,
|
|
91
|
-
"utf-8",
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
if (process.env.APITOGO_JSON_ONLY !== "1") {
|
|
95
|
-
// biome-ignore lint/suspicious/noConsole: Allowed here
|
|
96
|
-
console.log(colors.blue("✓ generated llms-full.txt"));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
1
|
+
import { writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import colors from "picocolors";
|
|
4
|
+
import { joinUrl } from "../lib/util/joinUrl.js";
|
|
5
|
+
import type { MarkdownFileInfo } from "./plugin-markdown-export.js";
|
|
6
|
+
export async function generateLlmsTxtFiles({
|
|
7
|
+
markdownFileInfos,
|
|
8
|
+
outputUrls,
|
|
9
|
+
baseOutputDir,
|
|
10
|
+
basePath,
|
|
11
|
+
siteName,
|
|
12
|
+
llmsTxt,
|
|
13
|
+
llmsTxtFull,
|
|
14
|
+
redirectUrls,
|
|
15
|
+
}: {
|
|
16
|
+
markdownFileInfos: MarkdownFileInfo[];
|
|
17
|
+
basePath: string | undefined;
|
|
18
|
+
outputUrls: string[];
|
|
19
|
+
baseOutputDir: string;
|
|
20
|
+
siteName?: string;
|
|
21
|
+
llmsTxt?: boolean;
|
|
22
|
+
llmsTxtFull?: boolean;
|
|
23
|
+
redirectUrls: Set<string>;
|
|
24
|
+
}) {
|
|
25
|
+
const nonRedirectUrls = outputUrls.filter((url) => !redirectUrls.has(url));
|
|
26
|
+
|
|
27
|
+
const baseUrl = basePath ?? "";
|
|
28
|
+
const title = siteName ?? "Documentation";
|
|
29
|
+
|
|
30
|
+
const markdownMap = new Map(
|
|
31
|
+
markdownFileInfos.map((info) => [info.routePath, info]),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// Generate llms.txt
|
|
35
|
+
if (llmsTxt) {
|
|
36
|
+
const llmsTxtParts: string[] = [];
|
|
37
|
+
|
|
38
|
+
llmsTxtParts.push(`# ${title}\n`);
|
|
39
|
+
llmsTxtParts.push("> Documentation files for Large Language Models\n");
|
|
40
|
+
|
|
41
|
+
// Add documentation section with links to all pages (matching sitemap structure)
|
|
42
|
+
llmsTxtParts.push("## Documentation\n");
|
|
43
|
+
|
|
44
|
+
for (const url of nonRedirectUrls) {
|
|
45
|
+
// Skip error pages
|
|
46
|
+
if (/(400|404|500)$/.test(url)) continue;
|
|
47
|
+
|
|
48
|
+
const mdInfo = markdownMap.get(url);
|
|
49
|
+
|
|
50
|
+
// Only include pages that have markdown content
|
|
51
|
+
if (mdInfo) {
|
|
52
|
+
// If we have markdown for this page, link to the .md file
|
|
53
|
+
const mdUrl = joinUrl(baseUrl, `${url}.md`);
|
|
54
|
+
const linkTitle = mdInfo.title ?? url;
|
|
55
|
+
const description = mdInfo.description ? `: ${mdInfo.description}` : "";
|
|
56
|
+
llmsTxtParts.push(`- [${linkTitle}](${mdUrl})${description}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const llmsTxt = llmsTxtParts.join("\n");
|
|
61
|
+
await writeFile(path.join(baseOutputDir, "llms.txt"), llmsTxt, "utf-8");
|
|
62
|
+
|
|
63
|
+
if (process.env.APITOGO_JSON_ONLY !== "1") {
|
|
64
|
+
// biome-ignore lint/suspicious/noConsole: Logging allowed here
|
|
65
|
+
console.log(colors.blue("✓ generated llms.txt"));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Generate llms-full.txt (full content of all markdown documents)
|
|
70
|
+
if (llmsTxtFull) {
|
|
71
|
+
const llmsFullParts: string[] = [];
|
|
72
|
+
|
|
73
|
+
llmsFullParts.push(`# ${title}\n`);
|
|
74
|
+
llmsFullParts.push("> Complete documentation for Large Language Models\n");
|
|
75
|
+
|
|
76
|
+
// Add each markdown document's full content
|
|
77
|
+
for (const info of markdownFileInfos) {
|
|
78
|
+
llmsFullParts.push(`\n---\n`);
|
|
79
|
+
llmsFullParts.push(`## Document: ${info.title ?? info.routePath}\n`);
|
|
80
|
+
if (info.description) {
|
|
81
|
+
llmsFullParts.push(`${info.description}\n`);
|
|
82
|
+
}
|
|
83
|
+
llmsFullParts.push(`URL: ${joinUrl(baseUrl, info.routePath)}\n`);
|
|
84
|
+
llmsFullParts.push(`\n${info.content}\n`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const llmsFull = llmsFullParts.join("\n");
|
|
88
|
+
await writeFile(
|
|
89
|
+
path.join(baseOutputDir, "llms-full.txt"),
|
|
90
|
+
llmsFull,
|
|
91
|
+
"utf-8",
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (process.env.APITOGO_JSON_ONLY !== "1") {
|
|
95
|
+
// biome-ignore lint/suspicious/noConsole: Allowed here
|
|
96
|
+
console.log(colors.blue("✓ generated llms-full.txt"));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -181,7 +181,9 @@ export const prerender = async ({
|
|
|
181
181
|
}
|
|
182
182
|
if (pagefindWriteResult?.outputPath) {
|
|
183
183
|
logger.info(
|
|
184
|
-
colors.blue(
|
|
184
|
+
colors.blue(
|
|
185
|
+
`✓ pagefind index built: ${pagefindWriteResult.outputPath}`,
|
|
186
|
+
),
|
|
185
187
|
);
|
|
186
188
|
}
|
|
187
189
|
}
|