@lukoweb/apitogo 0.1.1 → 0.1.3
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 +168 -57
- package/dist/declarations/lib/ui/Command.d.ts +1 -1
- package/dist/declarations/lib/util/MdxComponents.d.ts +1 -1
- package/package.json +2 -1
- package/src/app/main.tsx +150 -150
- package/src/config/loader.ts +245 -245
- package/src/index.ts +33 -33
- package/src/lib/authentication/components/CallbackHandler.tsx +45 -45
- package/src/lib/authentication/components/SignIn.tsx +46 -46
- package/src/lib/authentication/components/SignUp.tsx +48 -48
- package/src/lib/authentication/providers/clerk.tsx +224 -224
- package/src/lib/authentication/ui/AuthCard.tsx +7 -7
- package/src/lib/authentication/ui/EmailLinkCallbackUi.tsx +129 -125
- package/src/lib/authentication/ui/EmailLinkSentUi.tsx +105 -101
- package/src/lib/authentication/ui/EmailLinkSignInUi.tsx +100 -96
- package/src/lib/authentication/ui/EmailVerificationUi.tsx +128 -124
- package/src/lib/authentication/ui/ZudokuAuthUi.tsx +620 -616
- package/src/lib/components/AiAssistantMenuItems.tsx +102 -102
- package/src/lib/components/Autocomplete.tsx +123 -123
- package/src/lib/components/DeveloperHint.tsx +39 -35
- package/src/lib/components/Header.tsx +260 -260
- package/src/lib/components/Layout.tsx +53 -53
- package/src/lib/components/Main.tsx +51 -51
- package/src/lib/components/Mermaid.tsx +74 -70
- package/src/lib/components/MobileTopNavigation.tsx +276 -276
- package/src/lib/components/MultiSelect.tsx +86 -82
- package/src/lib/components/TopNavigation.tsx +103 -103
- package/src/lib/components/index.ts +26 -26
- package/src/lib/components/navigation/NavigationCategory.tsx +157 -157
- package/src/lib/components/navigation/NavigationFilterInput.tsx +35 -35
- package/src/lib/components/navigation/NavigationItem.tsx +181 -177
- package/src/lib/core/RouteGuard.tsx +193 -193
- package/src/lib/errors/ErrorMessage.tsx +50 -46
- package/src/lib/plugins/api-catalog/Catalog.tsx +80 -80
- package/src/lib/plugins/api-keys/CreateApiKey.tsx +128 -124
- package/src/lib/plugins/api-keys/CreateApiKeyDialog.tsx +49 -49
- package/src/lib/plugins/api-keys/SettingsApiKeys.tsx +72 -72
- package/src/lib/plugins/api-keys/settings/ApiKeyItem.tsx +342 -342
- package/src/lib/plugins/api-keys/settings/RevealApiKey.tsx +127 -127
- package/src/lib/plugins/markdown/MdxPage.tsx +285 -285
- package/src/lib/plugins/openapi/ApiHeader.tsx +96 -96
- package/src/lib/plugins/openapi/CollapsibleCode.tsx +88 -88
- package/src/lib/plugins/openapi/DownloadSchemaButton.tsx +94 -94
- package/src/lib/plugins/openapi/GeneratedExampleSidecarBox.tsx +52 -52
- package/src/lib/plugins/openapi/OperationListItem.tsx +183 -183
- package/src/lib/plugins/openapi/RequestBodySidecarBox.tsx +63 -63
- package/src/lib/plugins/openapi/ResponsesSidecarBox.tsx +120 -117
- package/src/lib/plugins/openapi/SchemaInfo.tsx +344 -344
- package/src/lib/plugins/openapi/SchemaList.tsx +113 -113
- package/src/lib/plugins/openapi/Sidecar.tsx +312 -309
- package/src/lib/plugins/openapi/SidecarExamples.tsx +177 -174
- package/src/lib/plugins/openapi/components/EnumValues.tsx +58 -58
- package/src/lib/plugins/openapi/components/ResponseContent.tsx +117 -114
- package/src/lib/plugins/openapi/playground/BodyPanel.tsx +274 -271
- package/src/lib/plugins/openapi/playground/CollapsibleHeader.tsx +51 -51
- package/src/lib/plugins/openapi/playground/ExamplesDropdown.tsx +60 -60
- package/src/lib/plugins/openapi/playground/Headers.tsx +188 -181
- package/src/lib/plugins/openapi/playground/IdentityDialog.tsx +75 -75
- package/src/lib/plugins/openapi/playground/IdentitySelector.tsx +38 -38
- package/src/lib/plugins/openapi/playground/ParamsGrid.tsx +45 -45
- package/src/lib/plugins/openapi/playground/Playground.tsx +602 -599
- package/src/lib/plugins/openapi/playground/PlaygroundDialog.tsx +56 -56
- package/src/lib/plugins/openapi/playground/QueryParams.tsx +151 -148
- package/src/lib/plugins/openapi/playground/RequestLoginDialog.tsx +70 -70
- package/src/lib/plugins/openapi/playground/request-panel/MultipartField.tsx +91 -91
- package/src/lib/plugins/openapi/playground/result-panel/AudioPlayer.tsx +50 -50
- package/src/lib/plugins/openapi/playground/result-panel/ResponseTab.tsx +355 -355
- package/src/lib/plugins/openapi/playground/result-panel/ResultPanel.tsx +106 -102
- package/src/lib/plugins/openapi/schema/SchemaPropertyItem.tsx +189 -184
- package/src/lib/plugins/openapi/schema/SchemaView.tsx +299 -299
- package/src/lib/plugins/search-pagefind/IndexingDialog.tsx +162 -162
- package/src/lib/plugins/search-pagefind/PagefindSearch.tsx +202 -202
- package/src/lib/plugins/search-pagefind/ResultList.tsx +122 -118
- package/src/lib/ui/ActionButton.tsx +21 -21
- package/src/lib/ui/Command.tsx +191 -191
- package/src/lib/util/MdxComponents.tsx +150 -150
- package/src/vite/config.ts +234 -231
- package/src/vite/dev-server.ts +291 -291
- package/src/vite/plugin-api-keys.ts +50 -50
- package/src/vite/plugin-api.ts +320 -318
- package/src/vite/plugin-auth.ts +38 -38
- package/src/vite/plugin-component.ts +45 -39
- package/src/vite/plugin-config.ts +75 -75
- package/src/vite/plugin-custom-pages.ts +36 -36
- package/src/vite/plugin-docs.ts +202 -202
- package/src/vite/plugin-markdown-export.ts +214 -214
- package/src/vite/plugin-mdx.ts +149 -149
- package/src/vite/plugin-navigation.ts +106 -106
- package/src/vite/plugin-search.ts +47 -47
- package/src/vite/plugin.ts +42 -42
- package/src/vite/prerender/prerender.ts +233 -233
|
@@ -1,214 +1,214 @@
|
|
|
1
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { matchPath } from "react-router";
|
|
4
|
-
import type { Plugin } from "vite";
|
|
5
|
-
import { getCurrentConfig } from "../config/loader.js";
|
|
6
|
-
import { ProtectedRoutesSchema } from "../config/validators/ProtectedRoutesSchema.js";
|
|
7
|
-
import { joinUrl } from "../lib/util/joinUrl.js";
|
|
8
|
-
import { readFrontmatter } from "../lib/util/readFrontmatter.js";
|
|
9
|
-
import {
|
|
10
|
-
globMarkdownFiles,
|
|
11
|
-
resolveCustomNavigationPaths,
|
|
12
|
-
} from "./plugin-docs.js";
|
|
13
|
-
|
|
14
|
-
export type MarkdownFileInfo = {
|
|
15
|
-
filePath: string;
|
|
16
|
-
routePath: string;
|
|
17
|
-
title?: string;
|
|
18
|
-
description?: string;
|
|
19
|
-
content: string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const processMarkdownFile = async (
|
|
23
|
-
filePath: string,
|
|
24
|
-
): Promise<{ content: string; title?: string; description?: string }> => {
|
|
25
|
-
const { content: markdownContent, data: frontmatter } =
|
|
26
|
-
await readFrontmatter(filePath);
|
|
27
|
-
|
|
28
|
-
let finalMarkdown = markdownContent;
|
|
29
|
-
if (frontmatter.title) {
|
|
30
|
-
// Add title as H1 at the beginning, matching the behavior in MdxPage.tsx
|
|
31
|
-
finalMarkdown = `# ${frontmatter.title}\n${markdownContent}`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
content: finalMarkdown,
|
|
36
|
-
title: frontmatter.title,
|
|
37
|
-
description: frontmatter.description,
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* This plugin exports markdown files (.md) for each document during the build process.
|
|
43
|
-
* In development mode, you can access documents at their URL path with .md extension
|
|
44
|
-
* (e.g., /foo/hello.md) to get the raw markdown without frontmatter.
|
|
45
|
-
*
|
|
46
|
-
* Markdown files are generated when:
|
|
47
|
-
* - publishMarkdown is enabled (for copy button functionality)
|
|
48
|
-
* - llmsTxt or llmsTxtFull is enabled (for generating llms.txt files)
|
|
49
|
-
*
|
|
50
|
-
* It also writes metadata to markdown-info.json used by the llms.txt generator.
|
|
51
|
-
*/
|
|
52
|
-
const viteMarkdownExportPlugin = (): Plugin => {
|
|
53
|
-
let markdownFiles: Record<string, string> = {};
|
|
54
|
-
let markdownFileInfos: MarkdownFileInfo[] = [];
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
name: "zudoku-markdown-export-plugin",
|
|
58
|
-
applyToEnvironment(env) {
|
|
59
|
-
return env.name === "ssr";
|
|
60
|
-
},
|
|
61
|
-
async buildStart() {
|
|
62
|
-
const config = getCurrentConfig();
|
|
63
|
-
const llmsConfig = config.docs?.llms;
|
|
64
|
-
|
|
65
|
-
const needsMdFiles =
|
|
66
|
-
config.docs?.publishMarkdown ||
|
|
67
|
-
llmsConfig?.llmsTxt ||
|
|
68
|
-
llmsConfig?.llmsTxtFull;
|
|
69
|
-
|
|
70
|
-
if (config.__meta.mode === "standalone" || !needsMdFiles) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
markdownFiles = await resolveCustomNavigationPaths(
|
|
75
|
-
config,
|
|
76
|
-
await globMarkdownFiles(config, { absolute: true }),
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
// Filter out protected routes unless `includeProtected` is true
|
|
80
|
-
if (!llmsConfig?.includeProtected) {
|
|
81
|
-
const protectedRoutes = ProtectedRoutesSchema.parse(
|
|
82
|
-
config.protectedRoutes,
|
|
83
|
-
);
|
|
84
|
-
if (protectedRoutes) {
|
|
85
|
-
const isProtectedRoute = (routePath: string): boolean => {
|
|
86
|
-
return Object.keys(protectedRoutes).some((route) =>
|
|
87
|
-
matchPath({ path: route, end: true }, routePath),
|
|
88
|
-
);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// Remove protected routes from the mapping
|
|
92
|
-
for (const routePath of Object.keys(markdownFiles)) {
|
|
93
|
-
if (isProtectedRoute(routePath)) {
|
|
94
|
-
delete markdownFiles[routePath];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
async configureServer(server) {
|
|
101
|
-
const config = getCurrentConfig();
|
|
102
|
-
const llmsConfig = config.docs?.llms;
|
|
103
|
-
|
|
104
|
-
// Serve .md files if markdown export is needed
|
|
105
|
-
const needsMdFiles =
|
|
106
|
-
config.docs?.publishMarkdown ||
|
|
107
|
-
llmsConfig?.llmsTxt ||
|
|
108
|
-
llmsConfig?.llmsTxtFull;
|
|
109
|
-
|
|
110
|
-
if (!needsMdFiles) return;
|
|
111
|
-
|
|
112
|
-
markdownFiles = await resolveCustomNavigationPaths(
|
|
113
|
-
config,
|
|
114
|
-
await globMarkdownFiles(config, { absolute: true }),
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
server.middlewares.use(async (req, res, next) => {
|
|
118
|
-
if (req.method !== "GET" || !req.url?.endsWith(".md")) {
|
|
119
|
-
return next();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const basePath = joinUrl(config.basePath);
|
|
123
|
-
const routePath = joinUrl(
|
|
124
|
-
req.url.slice(basePath.length).replace(/\.mdx?$/, ""),
|
|
125
|
-
);
|
|
126
|
-
const filePath = markdownFiles[routePath];
|
|
127
|
-
|
|
128
|
-
if (!filePath) return next();
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
const { content } = await processMarkdownFile(filePath);
|
|
132
|
-
res.setHeader("Content-Type", "text/markdown; charset=utf-8");
|
|
133
|
-
res.end(content);
|
|
134
|
-
} catch (error) {
|
|
135
|
-
// biome-ignore lint/suspicious/noConsole: Logging allowed here
|
|
136
|
-
console.warn(`Failed to serve markdown for ${routePath}:`, error);
|
|
137
|
-
return next();
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
},
|
|
141
|
-
async closeBundle() {
|
|
142
|
-
const config = getCurrentConfig();
|
|
143
|
-
const llmsConfig = config.docs?.llms;
|
|
144
|
-
|
|
145
|
-
const needsMdFiles =
|
|
146
|
-
config.docs?.publishMarkdown ||
|
|
147
|
-
llmsConfig?.llmsTxt ||
|
|
148
|
-
llmsConfig?.llmsTxtFull;
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
process.env.NODE_ENV !== "production" ||
|
|
152
|
-
Object.keys(markdownFiles).length === 0 ||
|
|
153
|
-
!needsMdFiles
|
|
154
|
-
) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// During build, write .md files to the dist directory
|
|
159
|
-
const distDir = path.join(
|
|
160
|
-
config.__meta.rootDir,
|
|
161
|
-
"dist",
|
|
162
|
-
config.basePath ?? "",
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
markdownFileInfos = [];
|
|
166
|
-
|
|
167
|
-
for (const [routePath, filePath] of Object.entries(markdownFiles)) {
|
|
168
|
-
try {
|
|
169
|
-
const {
|
|
170
|
-
content: finalMarkdown,
|
|
171
|
-
title,
|
|
172
|
-
description,
|
|
173
|
-
} = await processMarkdownFile(filePath);
|
|
174
|
-
|
|
175
|
-
markdownFileInfos.push({
|
|
176
|
-
filePath,
|
|
177
|
-
routePath,
|
|
178
|
-
title,
|
|
179
|
-
description,
|
|
180
|
-
content: finalMarkdown,
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
const segments =
|
|
184
|
-
routePath === "/"
|
|
185
|
-
? ["index"]
|
|
186
|
-
: routePath.split("/").filter(Boolean);
|
|
187
|
-
|
|
188
|
-
const outputPath = `${path.join(distDir, ...segments)}.md`;
|
|
189
|
-
|
|
190
|
-
await mkdir(path.dirname(outputPath), { recursive: true });
|
|
191
|
-
|
|
192
|
-
await writeFile(outputPath, finalMarkdown, "utf-8");
|
|
193
|
-
} catch (error) {
|
|
194
|
-
// biome-ignore lint/suspicious/noConsole: Logging allowed here
|
|
195
|
-
console.warn(`Failed to export markdown for ${routePath}:`, error);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (config.docs?.llms?.llmsTxt || config.docs?.llms?.llmsTxtFull) {
|
|
200
|
-
const markdownInfoPath = path.join(
|
|
201
|
-
config.__meta.rootDir,
|
|
202
|
-
"node_modules/.apitogo/markdown-info.json",
|
|
203
|
-
);
|
|
204
|
-
await writeFile(
|
|
205
|
-
markdownInfoPath,
|
|
206
|
-
JSON.stringify(markdownFileInfos, null, 2),
|
|
207
|
-
"utf-8",
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
export default viteMarkdownExportPlugin;
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { matchPath } from "react-router";
|
|
4
|
+
import type { Plugin } from "vite";
|
|
5
|
+
import { getCurrentConfig } from "../config/loader.js";
|
|
6
|
+
import { ProtectedRoutesSchema } from "../config/validators/ProtectedRoutesSchema.js";
|
|
7
|
+
import { joinUrl } from "../lib/util/joinUrl.js";
|
|
8
|
+
import { readFrontmatter } from "../lib/util/readFrontmatter.js";
|
|
9
|
+
import {
|
|
10
|
+
globMarkdownFiles,
|
|
11
|
+
resolveCustomNavigationPaths,
|
|
12
|
+
} from "./plugin-docs.js";
|
|
13
|
+
|
|
14
|
+
export type MarkdownFileInfo = {
|
|
15
|
+
filePath: string;
|
|
16
|
+
routePath: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
content: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const processMarkdownFile = async (
|
|
23
|
+
filePath: string,
|
|
24
|
+
): Promise<{ content: string; title?: string; description?: string }> => {
|
|
25
|
+
const { content: markdownContent, data: frontmatter } =
|
|
26
|
+
await readFrontmatter(filePath);
|
|
27
|
+
|
|
28
|
+
let finalMarkdown = markdownContent;
|
|
29
|
+
if (frontmatter.title) {
|
|
30
|
+
// Add title as H1 at the beginning, matching the behavior in MdxPage.tsx
|
|
31
|
+
finalMarkdown = `# ${frontmatter.title}\n${markdownContent}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
content: finalMarkdown,
|
|
36
|
+
title: frontmatter.title,
|
|
37
|
+
description: frontmatter.description,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* This plugin exports markdown files (.md) for each document during the build process.
|
|
43
|
+
* In development mode, you can access documents at their URL path with .md extension
|
|
44
|
+
* (e.g., /foo/hello.md) to get the raw markdown without frontmatter.
|
|
45
|
+
*
|
|
46
|
+
* Markdown files are generated when:
|
|
47
|
+
* - publishMarkdown is enabled (for copy button functionality)
|
|
48
|
+
* - llmsTxt or llmsTxtFull is enabled (for generating llms.txt files)
|
|
49
|
+
*
|
|
50
|
+
* It also writes metadata to markdown-info.json used by the llms.txt generator.
|
|
51
|
+
*/
|
|
52
|
+
const viteMarkdownExportPlugin = (): Plugin => {
|
|
53
|
+
let markdownFiles: Record<string, string> = {};
|
|
54
|
+
let markdownFileInfos: MarkdownFileInfo[] = [];
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
name: "zudoku-markdown-export-plugin",
|
|
58
|
+
applyToEnvironment(env) {
|
|
59
|
+
return env.name === "ssr";
|
|
60
|
+
},
|
|
61
|
+
async buildStart() {
|
|
62
|
+
const config = getCurrentConfig();
|
|
63
|
+
const llmsConfig = config.docs?.llms;
|
|
64
|
+
|
|
65
|
+
const needsMdFiles =
|
|
66
|
+
config.docs?.publishMarkdown ||
|
|
67
|
+
llmsConfig?.llmsTxt ||
|
|
68
|
+
llmsConfig?.llmsTxtFull;
|
|
69
|
+
|
|
70
|
+
if (config.__meta.mode === "standalone" || !needsMdFiles) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
markdownFiles = await resolveCustomNavigationPaths(
|
|
75
|
+
config,
|
|
76
|
+
await globMarkdownFiles(config, { absolute: true }),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// Filter out protected routes unless `includeProtected` is true
|
|
80
|
+
if (!llmsConfig?.includeProtected) {
|
|
81
|
+
const protectedRoutes = ProtectedRoutesSchema.parse(
|
|
82
|
+
config.protectedRoutes,
|
|
83
|
+
);
|
|
84
|
+
if (protectedRoutes) {
|
|
85
|
+
const isProtectedRoute = (routePath: string): boolean => {
|
|
86
|
+
return Object.keys(protectedRoutes).some((route) =>
|
|
87
|
+
matchPath({ path: route, end: true }, routePath),
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Remove protected routes from the mapping
|
|
92
|
+
for (const routePath of Object.keys(markdownFiles)) {
|
|
93
|
+
if (isProtectedRoute(routePath)) {
|
|
94
|
+
delete markdownFiles[routePath];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
async configureServer(server) {
|
|
101
|
+
const config = getCurrentConfig();
|
|
102
|
+
const llmsConfig = config.docs?.llms;
|
|
103
|
+
|
|
104
|
+
// Serve .md files if markdown export is needed
|
|
105
|
+
const needsMdFiles =
|
|
106
|
+
config.docs?.publishMarkdown ||
|
|
107
|
+
llmsConfig?.llmsTxt ||
|
|
108
|
+
llmsConfig?.llmsTxtFull;
|
|
109
|
+
|
|
110
|
+
if (!needsMdFiles) return;
|
|
111
|
+
|
|
112
|
+
markdownFiles = await resolveCustomNavigationPaths(
|
|
113
|
+
config,
|
|
114
|
+
await globMarkdownFiles(config, { absolute: true }),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
server.middlewares.use(async (req, res, next) => {
|
|
118
|
+
if (req.method !== "GET" || !req.url?.endsWith(".md")) {
|
|
119
|
+
return next();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const basePath = joinUrl(config.basePath);
|
|
123
|
+
const routePath = joinUrl(
|
|
124
|
+
req.url.slice(basePath.length).replace(/\.mdx?$/, ""),
|
|
125
|
+
);
|
|
126
|
+
const filePath = markdownFiles[routePath];
|
|
127
|
+
|
|
128
|
+
if (!filePath) return next();
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
const { content } = await processMarkdownFile(filePath);
|
|
132
|
+
res.setHeader("Content-Type", "text/markdown; charset=utf-8");
|
|
133
|
+
res.end(content);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
// biome-ignore lint/suspicious/noConsole: Logging allowed here
|
|
136
|
+
console.warn(`Failed to serve markdown for ${routePath}:`, error);
|
|
137
|
+
return next();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
async closeBundle() {
|
|
142
|
+
const config = getCurrentConfig();
|
|
143
|
+
const llmsConfig = config.docs?.llms;
|
|
144
|
+
|
|
145
|
+
const needsMdFiles =
|
|
146
|
+
config.docs?.publishMarkdown ||
|
|
147
|
+
llmsConfig?.llmsTxt ||
|
|
148
|
+
llmsConfig?.llmsTxtFull;
|
|
149
|
+
|
|
150
|
+
if (
|
|
151
|
+
process.env.NODE_ENV !== "production" ||
|
|
152
|
+
Object.keys(markdownFiles).length === 0 ||
|
|
153
|
+
!needsMdFiles
|
|
154
|
+
) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// During build, write .md files to the dist directory
|
|
159
|
+
const distDir = path.join(
|
|
160
|
+
config.__meta.rootDir,
|
|
161
|
+
"dist",
|
|
162
|
+
config.basePath ?? "",
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
markdownFileInfos = [];
|
|
166
|
+
|
|
167
|
+
for (const [routePath, filePath] of Object.entries(markdownFiles)) {
|
|
168
|
+
try {
|
|
169
|
+
const {
|
|
170
|
+
content: finalMarkdown,
|
|
171
|
+
title,
|
|
172
|
+
description,
|
|
173
|
+
} = await processMarkdownFile(filePath);
|
|
174
|
+
|
|
175
|
+
markdownFileInfos.push({
|
|
176
|
+
filePath,
|
|
177
|
+
routePath,
|
|
178
|
+
title,
|
|
179
|
+
description,
|
|
180
|
+
content: finalMarkdown,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const segments =
|
|
184
|
+
routePath === "/"
|
|
185
|
+
? ["index"]
|
|
186
|
+
: routePath.split("/").filter(Boolean);
|
|
187
|
+
|
|
188
|
+
const outputPath = `${path.join(distDir, ...segments)}.md`;
|
|
189
|
+
|
|
190
|
+
await mkdir(path.dirname(outputPath), { recursive: true });
|
|
191
|
+
|
|
192
|
+
await writeFile(outputPath, finalMarkdown, "utf-8");
|
|
193
|
+
} catch (error) {
|
|
194
|
+
// biome-ignore lint/suspicious/noConsole: Logging allowed here
|
|
195
|
+
console.warn(`Failed to export markdown for ${routePath}:`, error);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (config.docs?.llms?.llmsTxt || config.docs?.llms?.llmsTxtFull) {
|
|
200
|
+
const markdownInfoPath = path.join(
|
|
201
|
+
config.__meta.rootDir,
|
|
202
|
+
"node_modules/.apitogo/markdown-info.json",
|
|
203
|
+
);
|
|
204
|
+
await writeFile(
|
|
205
|
+
markdownInfoPath,
|
|
206
|
+
JSON.stringify(markdownFileInfos, null, 2),
|
|
207
|
+
"utf-8",
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
export default viteMarkdownExportPlugin;
|