boltdocs 1.0.1 → 1.3.0
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/{CodeBlock-37XMKCYY.mjs → CodeBlock-V3Z5EKGR.mjs} +0 -1
- package/dist/{PackageManagerTabs-4NWXLXQO.mjs → PackageManagerTabs-XEKI3L7P.mjs} +0 -2
- package/dist/{SearchDialog-FTOQZ763.mjs → SearchDialog-5EDRACEG.mjs} +1 -2
- package/dist/{SearchDialog-ZAZXYIFX.css → SearchDialog-X57WPTNN.css} +57 -129
- package/dist/{Video-I6QY4X7J.mjs → Video-KNTY5BNO.mjs} +0 -1
- package/dist/cache-EHR7SXRU.mjs +12 -0
- package/dist/chunk-GSYECEZY.mjs +381 -0
- package/dist/{chunk-ZFCOLEXN.mjs → chunk-NS7WHDYA.mjs} +234 -426
- package/dist/client/index.css +57 -129
- package/dist/client/index.d.mts +39 -8
- package/dist/client/index.d.ts +39 -8
- package/dist/client/index.js +557 -564
- package/dist/client/index.mjs +305 -18
- package/dist/client/ssr.css +57 -129
- package/dist/client/ssr.d.mts +1 -1
- package/dist/client/ssr.d.ts +1 -1
- package/dist/client/ssr.js +257 -558
- package/dist/client/ssr.mjs +1 -2
- package/dist/{config-D2XmHJYe.d.mts → config-BD5ZHz15.d.mts} +7 -0
- package/dist/{config-D2XmHJYe.d.ts → config-BD5ZHz15.d.ts} +7 -0
- package/dist/node/index.d.mts +2 -2
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.js +457 -118
- package/dist/node/index.mjs +144 -147
- package/dist/{index-CRQKWAeo.d.mts → types-CvrzTbEX.d.mts} +1 -28
- package/dist/{index-CRQKWAeo.d.ts → types-CvrzTbEX.d.ts} +1 -28
- package/package.json +2 -2
- package/src/client/app/index.tsx +32 -110
- package/src/client/app/preload.tsx +1 -1
- package/src/client/index.ts +1 -1
- package/src/client/ssr.tsx +2 -1
- package/src/client/theme/components/Playground/Playground.tsx +40 -2
- package/src/client/theme/components/mdx/mdx-components.css +39 -20
- package/src/client/theme/styles/markdown.css +4 -4
- package/src/client/theme/styles.css +0 -1
- package/src/client/theme/ui/Breadcrumbs/Breadcrumbs.tsx +1 -1
- package/src/client/theme/ui/LanguageSwitcher/LanguageSwitcher.tsx +1 -1
- package/src/client/theme/ui/Layout/Layout.tsx +3 -14
- package/src/client/theme/ui/Layout/responsive.css +0 -4
- package/src/client/theme/ui/Link/Link.tsx +52 -0
- package/src/client/theme/ui/Navbar/Navbar.tsx +1 -1
- package/src/client/theme/ui/NotFound/NotFound.tsx +0 -1
- package/src/client/theme/ui/OnThisPage/OnThisPage.tsx +45 -2
- package/src/client/theme/ui/SearchDialog/SearchDialog.tsx +1 -1
- package/src/client/theme/ui/Sidebar/Sidebar.tsx +44 -40
- package/src/client/theme/ui/Sidebar/sidebar.css +25 -58
- package/src/client/theme/ui/VersionSwitcher/VersionSwitcher.tsx +1 -1
- package/src/client/types.ts +50 -0
- package/src/node/cache.ts +360 -46
- package/src/node/config.ts +7 -0
- package/src/node/mdx.ts +83 -4
- package/src/node/plugin/index.ts +3 -0
- package/src/node/routes/cache.ts +5 -1
- package/src/node/routes/index.ts +17 -2
- package/src/node/ssg/index.ts +4 -0
- package/dist/Playground-OE2OE6B6.mjs +0 -7
- package/dist/chunk-PN4GCTYG.mjs +0 -67
- package/dist/chunk-X2TDGMTR.mjs +0 -64
- package/dist/chunk-X6BYQHVC.mjs +0 -12
- package/dist/node/cli/index.d.mts +0 -1
- package/dist/node/cli/index.d.ts +0 -1
- package/dist/node/cli/index.js +0 -199
- package/dist/node/cli/index.mjs +0 -154
- package/src/client/theme/styles/home.css +0 -60
package/dist/node/index.mjs
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
FileCache,
|
|
3
|
+
TransformCache,
|
|
4
|
+
capitalize,
|
|
5
|
+
escapeHtml,
|
|
6
|
+
extractNumberPrefix,
|
|
7
|
+
fileToRoutePath,
|
|
8
|
+
isDocFile,
|
|
9
|
+
normalizePath,
|
|
10
|
+
parseFrontmatter,
|
|
11
|
+
stripNumberPrefix
|
|
12
|
+
} from "../chunk-GSYECEZY.mjs";
|
|
7
13
|
|
|
8
14
|
// src/node/plugin/index.ts
|
|
9
15
|
import { loadEnv } from "vite";
|
|
@@ -11,130 +17,8 @@ import { loadEnv } from "vite";
|
|
|
11
17
|
// src/node/routes/index.ts
|
|
12
18
|
import fastGlob from "fast-glob";
|
|
13
19
|
|
|
14
|
-
// src/node/utils.ts
|
|
15
|
-
import fs from "fs";
|
|
16
|
-
import matter from "gray-matter";
|
|
17
|
-
function normalizePath(p) {
|
|
18
|
-
return p.replace(/\\/g, "/");
|
|
19
|
-
}
|
|
20
|
-
function stripNumberPrefix(name) {
|
|
21
|
-
return name.replace(/^\d+\./, "");
|
|
22
|
-
}
|
|
23
|
-
function extractNumberPrefix(name) {
|
|
24
|
-
const match = name.match(/^(\d+)\./);
|
|
25
|
-
return match ? parseInt(match[1], 10) : void 0;
|
|
26
|
-
}
|
|
27
|
-
function isDocFile(filePath) {
|
|
28
|
-
return /\.mdx?$/.test(filePath);
|
|
29
|
-
}
|
|
30
|
-
function getFileMtime(filePath) {
|
|
31
|
-
try {
|
|
32
|
-
return fs.statSync(filePath).mtimeMs;
|
|
33
|
-
} catch {
|
|
34
|
-
return 0;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
function parseFrontmatter(filePath) {
|
|
38
|
-
const raw = fs.readFileSync(filePath, "utf-8");
|
|
39
|
-
const { data, content } = matter(raw);
|
|
40
|
-
return { data, content };
|
|
41
|
-
}
|
|
42
|
-
function escapeHtml(str) {
|
|
43
|
-
return str.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
44
|
-
}
|
|
45
|
-
function fileToRoutePath(relativePath) {
|
|
46
|
-
let cleanedPath = relativePath.split("/").map(stripNumberPrefix).join("/");
|
|
47
|
-
let routePath = cleanedPath.replace(/\.mdx?$/, "");
|
|
48
|
-
if (routePath === "index" || routePath.endsWith("/index")) {
|
|
49
|
-
routePath = routePath.replace(/index$/, "");
|
|
50
|
-
}
|
|
51
|
-
if (!routePath.startsWith("/")) {
|
|
52
|
-
routePath = "/" + routePath;
|
|
53
|
-
}
|
|
54
|
-
if (routePath.length > 1 && routePath.endsWith("/")) {
|
|
55
|
-
routePath = routePath.slice(0, -1);
|
|
56
|
-
}
|
|
57
|
-
return routePath;
|
|
58
|
-
}
|
|
59
|
-
function capitalize(str) {
|
|
60
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// src/node/cache.ts
|
|
64
|
-
var FileCache = class {
|
|
65
|
-
entries = /* @__PURE__ */ new Map();
|
|
66
|
-
/**
|
|
67
|
-
* Retrieves parsed data for a file from the cache.
|
|
68
|
-
* Compares the current filesystem mtime with the cached mtime.
|
|
69
|
-
*
|
|
70
|
-
* @param filePath - The absolute path of the file
|
|
71
|
-
* @returns The cached data if valid, or `null` if the file has changed or doesn't exist
|
|
72
|
-
*/
|
|
73
|
-
get(filePath) {
|
|
74
|
-
const entry = this.entries.get(filePath);
|
|
75
|
-
if (!entry) return null;
|
|
76
|
-
const currentMtime = getFileMtime(filePath);
|
|
77
|
-
if (currentMtime !== entry.mtime) return null;
|
|
78
|
-
return entry.data;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Stores parsed data for a file in the cache, recording its current mtime.
|
|
82
|
-
*
|
|
83
|
-
* @param filePath - The absolute path to the file
|
|
84
|
-
* @param data - The parsed data to store
|
|
85
|
-
*/
|
|
86
|
-
set(filePath, data) {
|
|
87
|
-
this.entries.set(filePath, {
|
|
88
|
-
data,
|
|
89
|
-
mtime: getFileMtime(filePath)
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Checks if a specific file's cache is still valid (based on its mtime).
|
|
94
|
-
*
|
|
95
|
-
* @param filePath - The absolute path to the file
|
|
96
|
-
* @returns `true` if the cache is valid, `false` otherwise
|
|
97
|
-
*/
|
|
98
|
-
isValid(filePath) {
|
|
99
|
-
return this.get(filePath) !== null;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Manually removes a specific file from the cache.
|
|
103
|
-
* Useful when forcefully invalidating a single updated file.
|
|
104
|
-
*
|
|
105
|
-
* @param filePath - The absolute path to the file
|
|
106
|
-
*/
|
|
107
|
-
invalidate(filePath) {
|
|
108
|
-
this.entries.delete(filePath);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Clears the entire cache, forcing all files to be re-parsed on the next request.
|
|
112
|
-
* Useful when global dependencies (like config) change.
|
|
113
|
-
*/
|
|
114
|
-
invalidateAll() {
|
|
115
|
-
this.entries.clear();
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Removes cached entries for files that no longer exist on the filesystem.
|
|
119
|
-
* Prevents memory leaks from deleted files.
|
|
120
|
-
*
|
|
121
|
-
* @param currentFiles - A Set of absolute file paths currently discovered on the disk
|
|
122
|
-
*/
|
|
123
|
-
pruneStale(currentFiles) {
|
|
124
|
-
for (const key of this.entries.keys()) {
|
|
125
|
-
if (!currentFiles.has(key)) {
|
|
126
|
-
this.entries.delete(key);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/** Number of cached entries */
|
|
131
|
-
get size() {
|
|
132
|
-
return this.entries.size;
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
|
|
136
20
|
// src/node/routes/cache.ts
|
|
137
|
-
var docCache = new FileCache();
|
|
21
|
+
var docCache = new FileCache({ name: "routes" });
|
|
138
22
|
function invalidateRouteCache() {
|
|
139
23
|
docCache.invalidateAll();
|
|
140
24
|
}
|
|
@@ -247,6 +131,7 @@ function compareByGroupPosition(a, b) {
|
|
|
247
131
|
|
|
248
132
|
// src/node/routes/index.ts
|
|
249
133
|
async function generateRoutes(docsDir, config, basePath = "/docs") {
|
|
134
|
+
docCache.load();
|
|
250
135
|
const files = await fastGlob(["**/*.md", "**/*.mdx"], {
|
|
251
136
|
cwd: docsDir,
|
|
252
137
|
absolute: true
|
|
@@ -255,15 +140,25 @@ async function generateRoutes(docsDir, config, basePath = "/docs") {
|
|
|
255
140
|
if (config?.i18n) {
|
|
256
141
|
docCache.invalidateAll();
|
|
257
142
|
}
|
|
143
|
+
let cacheHits = 0;
|
|
258
144
|
const parsed = await Promise.all(
|
|
259
145
|
files.map(async (file) => {
|
|
260
146
|
const cached = docCache.get(file);
|
|
261
|
-
if (cached)
|
|
147
|
+
if (cached) {
|
|
148
|
+
cacheHits++;
|
|
149
|
+
return cached;
|
|
150
|
+
}
|
|
262
151
|
const result = parseDocFile(file, docsDir, basePath, config);
|
|
263
152
|
docCache.set(file, result);
|
|
264
153
|
return result;
|
|
265
154
|
})
|
|
266
155
|
);
|
|
156
|
+
if (files.length > 0) {
|
|
157
|
+
console.log(
|
|
158
|
+
`[boltdocs] Routes generated: ${files.length} files (${cacheHits} from cache, ${files.length - cacheHits} parsed)`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
docCache.save();
|
|
267
162
|
const groupMeta = /* @__PURE__ */ new Map();
|
|
268
163
|
for (const p of parsed) {
|
|
269
164
|
if (p.relativeDir) {
|
|
@@ -338,12 +233,60 @@ async function generateRoutes(docsDir, config, basePath = "/docs") {
|
|
|
338
233
|
}
|
|
339
234
|
|
|
340
235
|
// src/node/plugin/index.ts
|
|
341
|
-
init_config();
|
|
342
236
|
import { ViteImageOptimizer } from "vite-plugin-image-optimizer";
|
|
343
237
|
|
|
238
|
+
// src/node/config.ts
|
|
239
|
+
import path2 from "path";
|
|
240
|
+
import { pathToFileURL } from "url";
|
|
241
|
+
import fs from "fs";
|
|
242
|
+
var CONFIG_FILES = [
|
|
243
|
+
"boltdocs.config.js",
|
|
244
|
+
"boltdocs.config.mjs",
|
|
245
|
+
"boltdocs.config.ts"
|
|
246
|
+
];
|
|
247
|
+
async function resolveConfig(docsDir) {
|
|
248
|
+
const projectRoot = process.cwd();
|
|
249
|
+
const defaults = {
|
|
250
|
+
docsDir: path2.resolve(docsDir),
|
|
251
|
+
themeConfig: {
|
|
252
|
+
title: "Boltdocs",
|
|
253
|
+
description: "A Vite documentation framework",
|
|
254
|
+
navbar: [
|
|
255
|
+
{ text: "Home", link: "/" },
|
|
256
|
+
{ text: "Documentation", link: "/docs" }
|
|
257
|
+
]
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
for (const filename of CONFIG_FILES) {
|
|
261
|
+
const configPath = path2.resolve(projectRoot, filename);
|
|
262
|
+
if (fs.existsSync(configPath)) {
|
|
263
|
+
try {
|
|
264
|
+
const fileUrl = pathToFileURL(configPath).href + "?t=" + Date.now();
|
|
265
|
+
const mod = await import(fileUrl);
|
|
266
|
+
const userConfig = mod.default || mod;
|
|
267
|
+
const userThemeConfig = userConfig.themeConfig || userConfig;
|
|
268
|
+
return {
|
|
269
|
+
docsDir: path2.resolve(docsDir),
|
|
270
|
+
themeConfig: {
|
|
271
|
+
...defaults.themeConfig,
|
|
272
|
+
...userThemeConfig
|
|
273
|
+
},
|
|
274
|
+
i18n: userConfig.i18n,
|
|
275
|
+
versions: userConfig.versions,
|
|
276
|
+
siteUrl: userConfig.siteUrl,
|
|
277
|
+
plugins: userConfig.plugins || []
|
|
278
|
+
};
|
|
279
|
+
} catch (e) {
|
|
280
|
+
console.warn(`[boltdocs] Failed to load config from ${filename}:`, e);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return defaults;
|
|
285
|
+
}
|
|
286
|
+
|
|
344
287
|
// src/node/ssg/index.ts
|
|
345
288
|
import fs2 from "fs";
|
|
346
|
-
import
|
|
289
|
+
import path3 from "path";
|
|
347
290
|
import { fileURLToPath } from "url";
|
|
348
291
|
import { createRequire } from "module";
|
|
349
292
|
|
|
@@ -407,14 +350,14 @@ ${entries.map(
|
|
|
407
350
|
|
|
408
351
|
// src/node/ssg/index.ts
|
|
409
352
|
var _filename = fileURLToPath(import.meta.url);
|
|
410
|
-
var _dirname =
|
|
353
|
+
var _dirname = path3.dirname(_filename);
|
|
411
354
|
var _require = createRequire(import.meta.url);
|
|
412
355
|
async function generateStaticPages(options) {
|
|
413
356
|
const { docsDir, outDir, config } = options;
|
|
414
357
|
const routes = await generateRoutes(docsDir, config);
|
|
415
358
|
const siteTitle = config?.themeConfig?.title || "Boltdocs";
|
|
416
359
|
const siteDescription = config?.themeConfig?.description || "";
|
|
417
|
-
const ssrModulePath =
|
|
360
|
+
const ssrModulePath = path3.resolve(_dirname, "../client/ssr.js");
|
|
418
361
|
if (!fs2.existsSync(ssrModulePath)) {
|
|
419
362
|
console.error(
|
|
420
363
|
"[boltdocs] SSR module not found at",
|
|
@@ -424,7 +367,7 @@ async function generateStaticPages(options) {
|
|
|
424
367
|
return;
|
|
425
368
|
}
|
|
426
369
|
const { render } = _require(ssrModulePath);
|
|
427
|
-
const templatePath =
|
|
370
|
+
const templatePath = path3.join(outDir, "index.html");
|
|
428
371
|
if (!fs2.existsSync(templatePath)) {
|
|
429
372
|
console.warn("[boltdocs] No index.html found in outDir, skipping SSG.");
|
|
430
373
|
return;
|
|
@@ -455,10 +398,10 @@ async function generateStaticPages(options) {
|
|
|
455
398
|
title: escapeHtml(pageTitle),
|
|
456
399
|
description: escapeHtml(pageDescription)
|
|
457
400
|
}).replace("<!--app-html-->", appHtml).replace(`<div id="root"></div>`, `<div id="root">${appHtml}</div>`);
|
|
458
|
-
const routeDir =
|
|
401
|
+
const routeDir = path3.join(outDir, route.path);
|
|
459
402
|
await fs2.promises.mkdir(routeDir, { recursive: true });
|
|
460
403
|
await fs2.promises.writeFile(
|
|
461
|
-
|
|
404
|
+
path3.join(routeDir, "index.html"),
|
|
462
405
|
html,
|
|
463
406
|
"utf-8"
|
|
464
407
|
);
|
|
@@ -471,14 +414,16 @@ async function generateStaticPages(options) {
|
|
|
471
414
|
routes.map((r) => r.path),
|
|
472
415
|
config
|
|
473
416
|
);
|
|
474
|
-
fs2.writeFileSync(
|
|
417
|
+
fs2.writeFileSync(path3.join(outDir, "sitemap.xml"), sitemap, "utf-8");
|
|
475
418
|
console.log(
|
|
476
419
|
`[boltdocs] Generated ${routes.length} static pages + sitemap.xml`
|
|
477
420
|
);
|
|
421
|
+
const { flushCache } = await import("../cache-EHR7SXRU.mjs");
|
|
422
|
+
await flushCache();
|
|
478
423
|
}
|
|
479
424
|
|
|
480
425
|
// src/node/plugin/index.ts
|
|
481
|
-
import
|
|
426
|
+
import path4 from "path";
|
|
482
427
|
|
|
483
428
|
// src/node/plugin/entry.ts
|
|
484
429
|
function generateEntryCode(options, config) {
|
|
@@ -489,8 +434,8 @@ function generateEntryCode(options, config) {
|
|
|
489
434
|
const componentImports = pluginComponents.map(
|
|
490
435
|
([
|
|
491
436
|
name,
|
|
492
|
-
|
|
493
|
-
]) => `import * as _comp_${name} from '${normalizePath(
|
|
437
|
+
path5
|
|
438
|
+
]) => `import * as _comp_${name} from '${normalizePath(path5)}';
|
|
494
439
|
const ${name} = _comp_${name}.default || _comp_${name}['${name}'] || _comp_${name};`
|
|
495
440
|
).join("\n");
|
|
496
441
|
const componentMap = pluginComponents.map(([name]) => name).join(", ");
|
|
@@ -560,7 +505,7 @@ ${themeScript} </head>`);
|
|
|
560
505
|
|
|
561
506
|
// src/node/plugin/index.ts
|
|
562
507
|
function boltdocsPlugin(options = {}, passedConfig) {
|
|
563
|
-
const docsDir =
|
|
508
|
+
const docsDir = path4.resolve(process.cwd(), options.docsDir || "docs");
|
|
564
509
|
const normalizedDocsDir = normalizePath(docsDir);
|
|
565
510
|
let config = passedConfig;
|
|
566
511
|
let viteConfig;
|
|
@@ -590,7 +535,7 @@ function boltdocsPlugin(options = {}, passedConfig) {
|
|
|
590
535
|
},
|
|
591
536
|
configureServer(server) {
|
|
592
537
|
const configPaths = CONFIG_FILES.map(
|
|
593
|
-
(c) =>
|
|
538
|
+
(c) => path4.resolve(process.cwd(), c)
|
|
594
539
|
);
|
|
595
540
|
server.watcher.add(configPaths);
|
|
596
541
|
const handleFileEvent = async (file, type) => {
|
|
@@ -653,8 +598,10 @@ function boltdocsPlugin(options = {}, passedConfig) {
|
|
|
653
598
|
},
|
|
654
599
|
async closeBundle() {
|
|
655
600
|
if (!isBuild) return;
|
|
656
|
-
const outDir = viteConfig?.build?.outDir ?
|
|
601
|
+
const outDir = viteConfig?.build?.outDir ? path4.resolve(viteConfig.root, viteConfig.build.outDir) : path4.resolve(process.cwd(), "dist");
|
|
657
602
|
await generateStaticPages({ docsDir, outDir, config });
|
|
603
|
+
const { flushCache } = await import("../cache-EHR7SXRU.mjs");
|
|
604
|
+
await flushCache();
|
|
658
605
|
}
|
|
659
606
|
},
|
|
660
607
|
ViteImageOptimizer({
|
|
@@ -684,10 +631,13 @@ import remarkGfm from "remark-gfm";
|
|
|
684
631
|
import remarkFrontmatter from "remark-frontmatter";
|
|
685
632
|
import rehypeSlug from "rehype-slug";
|
|
686
633
|
import rehypePrettyCode from "rehype-pretty-code";
|
|
634
|
+
import crypto from "crypto";
|
|
635
|
+
var mdxCache = new TransformCache("mdx");
|
|
636
|
+
var mdxCacheLoaded = false;
|
|
687
637
|
function boltdocsMdxPlugin(config) {
|
|
688
638
|
const extraRemarkPlugins = config?.plugins?.flatMap((p) => p.remarkPlugins || []) || [];
|
|
689
639
|
const extraRehypePlugins = config?.plugins?.flatMap((p) => p.rehypePlugins || []) || [];
|
|
690
|
-
|
|
640
|
+
const baseMdxPlugin = mdxPlugin({
|
|
691
641
|
remarkPlugins: [remarkGfm, remarkFrontmatter, ...extraRemarkPlugins],
|
|
692
642
|
rehypePlugins: [
|
|
693
643
|
rehypeSlug,
|
|
@@ -695,19 +645,66 @@ function boltdocsMdxPlugin(config) {
|
|
|
695
645
|
[
|
|
696
646
|
rehypePrettyCode,
|
|
697
647
|
{
|
|
698
|
-
theme: "one-dark-pro",
|
|
648
|
+
theme: config?.themeConfig?.codeTheme || "one-dark-pro",
|
|
699
649
|
keepBackground: false
|
|
700
650
|
}
|
|
701
651
|
]
|
|
702
652
|
],
|
|
703
|
-
// Provide React as default for JSX
|
|
704
653
|
jsxRuntime: "automatic",
|
|
705
654
|
providerImportSource: "@mdx-js/react"
|
|
706
655
|
});
|
|
656
|
+
return {
|
|
657
|
+
...baseMdxPlugin,
|
|
658
|
+
name: "vite-plugin-boltdocs-mdx",
|
|
659
|
+
async buildStart() {
|
|
660
|
+
hits = 0;
|
|
661
|
+
total = 0;
|
|
662
|
+
if (!mdxCacheLoaded) {
|
|
663
|
+
mdxCache.load();
|
|
664
|
+
mdxCacheLoaded = true;
|
|
665
|
+
}
|
|
666
|
+
if (baseMdxPlugin.buildStart) {
|
|
667
|
+
await baseMdxPlugin.buildStart.call(this);
|
|
668
|
+
}
|
|
669
|
+
},
|
|
670
|
+
async transform(code, id, options) {
|
|
671
|
+
if (!id.endsWith(".md") && !id.endsWith(".mdx")) {
|
|
672
|
+
return baseMdxPlugin.transform?.call(this, code, id, options);
|
|
673
|
+
}
|
|
674
|
+
total++;
|
|
675
|
+
const contentHash = crypto.createHash("md5").update(code).digest("hex");
|
|
676
|
+
const cacheKey = `${id}:${contentHash}`;
|
|
677
|
+
const cached = mdxCache.get(cacheKey);
|
|
678
|
+
if (cached) {
|
|
679
|
+
hits++;
|
|
680
|
+
return { code: cached, map: null };
|
|
681
|
+
}
|
|
682
|
+
const result = await baseMdxPlugin.transform.call(
|
|
683
|
+
this,
|
|
684
|
+
code,
|
|
685
|
+
id,
|
|
686
|
+
options
|
|
687
|
+
);
|
|
688
|
+
if (result && typeof result === "object" && result.code) {
|
|
689
|
+
mdxCache.set(cacheKey, result.code);
|
|
690
|
+
} else if (typeof result === "string") {
|
|
691
|
+
mdxCache.set(cacheKey, result);
|
|
692
|
+
}
|
|
693
|
+
return result;
|
|
694
|
+
},
|
|
695
|
+
async buildEnd() {
|
|
696
|
+
mdxCache.save();
|
|
697
|
+
await mdxCache.flush();
|
|
698
|
+
if (baseMdxPlugin.buildEnd) {
|
|
699
|
+
await baseMdxPlugin.buildEnd.call(this);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
};
|
|
707
703
|
}
|
|
704
|
+
var hits = 0;
|
|
705
|
+
var total = 0;
|
|
708
706
|
|
|
709
707
|
// src/node/index.ts
|
|
710
|
-
init_config();
|
|
711
708
|
async function boltdocs(options) {
|
|
712
709
|
const docsDir = options?.docsDir || "docs";
|
|
713
710
|
const config = await resolveConfig(docsDir);
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
declare global {
|
|
4
|
-
interface ImportMeta {
|
|
5
|
-
env: Record<string, any>;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
3
|
/**
|
|
9
4
|
* Metadata provided by the server for a specific route.
|
|
10
5
|
* Maps closely to the `RouteMeta` type in the Node environment.
|
|
@@ -56,27 +51,5 @@ interface CreateBoltdocsAppOptions {
|
|
|
56
51
|
/** Optional custom MDX components provided by plugins */
|
|
57
52
|
components?: Record<string, React.ComponentType<any>>;
|
|
58
53
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Creates and mounts the Boltdocs documentation app.
|
|
61
|
-
*
|
|
62
|
-
* Usage:
|
|
63
|
-
* ```tsx
|
|
64
|
-
* import { createBoltdocsApp } from 'boltdocs/client'
|
|
65
|
-
* import routes from 'virtual:boltdocs-routes'
|
|
66
|
-
* import config from 'virtual:boltdocs-config'
|
|
67
|
-
* import 'boltdocs/style.css'
|
|
68
|
-
* import HomePage from './HomePage'
|
|
69
|
-
*
|
|
70
|
-
* createBoltdocsApp({
|
|
71
|
-
* target: '#root',
|
|
72
|
-
* routes,
|
|
73
|
-
* config,
|
|
74
|
-
* modules: import.meta.glob('/docs/**\/*.{md,mdx}'),
|
|
75
|
-
* hot: import.meta.hot,
|
|
76
|
-
* homePage: HomePage,
|
|
77
|
-
* })
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
declare function createBoltdocsApp(options: CreateBoltdocsAppOptions): void;
|
|
81
54
|
|
|
82
|
-
export {
|
|
55
|
+
export type { CreateBoltdocsAppOptions as C, ComponentRoute as a };
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
declare global {
|
|
4
|
-
interface ImportMeta {
|
|
5
|
-
env: Record<string, any>;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
3
|
/**
|
|
9
4
|
* Metadata provided by the server for a specific route.
|
|
10
5
|
* Maps closely to the `RouteMeta` type in the Node environment.
|
|
@@ -56,27 +51,5 @@ interface CreateBoltdocsAppOptions {
|
|
|
56
51
|
/** Optional custom MDX components provided by plugins */
|
|
57
52
|
components?: Record<string, React.ComponentType<any>>;
|
|
58
53
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Creates and mounts the Boltdocs documentation app.
|
|
61
|
-
*
|
|
62
|
-
* Usage:
|
|
63
|
-
* ```tsx
|
|
64
|
-
* import { createBoltdocsApp } from 'boltdocs/client'
|
|
65
|
-
* import routes from 'virtual:boltdocs-routes'
|
|
66
|
-
* import config from 'virtual:boltdocs-config'
|
|
67
|
-
* import 'boltdocs/style.css'
|
|
68
|
-
* import HomePage from './HomePage'
|
|
69
|
-
*
|
|
70
|
-
* createBoltdocsApp({
|
|
71
|
-
* target: '#root',
|
|
72
|
-
* routes,
|
|
73
|
-
* config,
|
|
74
|
-
* modules: import.meta.glob('/docs/**\/*.{md,mdx}'),
|
|
75
|
-
* hot: import.meta.hot,
|
|
76
|
-
* homePage: HomePage,
|
|
77
|
-
* })
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
declare function createBoltdocsApp(options: CreateBoltdocsAppOptions): void;
|
|
81
54
|
|
|
82
|
-
export {
|
|
55
|
+
export type { CreateBoltdocsAppOptions as C, ComponentRoute as a };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "boltdocs",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "A lightweight documentation generator for React projects.",
|
|
5
5
|
"main": "dist/node/index.js",
|
|
6
6
|
"module": "dist/node/index.mjs",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"remark-gfm": "^4.0.1",
|
|
55
55
|
"sharp": "^0.34.5",
|
|
56
56
|
"shiki": "^3.23.0",
|
|
57
|
-
"svgo": "^4.0.
|
|
57
|
+
"svgo": "^4.0.1",
|
|
58
58
|
"unist-util-visit": "^5.1.0",
|
|
59
59
|
"vite": "^7.3.1",
|
|
60
60
|
"vite-plugin-image-optimizer": "^2.0.3"
|