boltdocs 1.0.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.
Files changed (137) hide show
  1. package/dist/CodeBlock-37XMKCYY.mjs +7 -0
  2. package/dist/PackageManagerTabs-4NWXLXQO.mjs +314 -0
  3. package/dist/Playground-OE2OE6B6.mjs +7 -0
  4. package/dist/SearchDialog-FTOQZ763.mjs +187 -0
  5. package/dist/SearchDialog-ZAZXYIFX.css +2147 -0
  6. package/dist/Video-I6QY4X7J.mjs +7 -0
  7. package/dist/chunk-2YRDWM6O.mjs +56 -0
  8. package/dist/chunk-PN4GCTYG.mjs +67 -0
  9. package/dist/chunk-X2TDGMTR.mjs +64 -0
  10. package/dist/chunk-X6BYQHVC.mjs +12 -0
  11. package/dist/chunk-Z7JHYNAS.mjs +57 -0
  12. package/dist/chunk-ZFCOLEXN.mjs +1644 -0
  13. package/dist/client/index.css +2147 -0
  14. package/dist/client/index.d.mts +298 -0
  15. package/dist/client/index.d.ts +298 -0
  16. package/dist/client/index.js +2793 -0
  17. package/dist/client/index.mjs +63 -0
  18. package/dist/client/ssr.css +2147 -0
  19. package/dist/client/ssr.d.mts +25 -0
  20. package/dist/client/ssr.d.ts +25 -0
  21. package/dist/client/ssr.js +2727 -0
  22. package/dist/client/ssr.mjs +32 -0
  23. package/dist/config-D2XmHJYe.d.mts +122 -0
  24. package/dist/config-D2XmHJYe.d.ts +122 -0
  25. package/dist/index-CRQKWAeo.d.mts +82 -0
  26. package/dist/index-CRQKWAeo.d.ts +82 -0
  27. package/dist/node/cli/index.d.mts +1 -0
  28. package/dist/node/cli/index.d.ts +1 -0
  29. package/dist/node/cli/index.js +199 -0
  30. package/dist/node/cli/index.mjs +154 -0
  31. package/dist/node/index.d.mts +79 -0
  32. package/dist/node/index.d.ts +79 -0
  33. package/dist/node/index.js +797 -0
  34. package/dist/node/index.mjs +719 -0
  35. package/package.json +79 -0
  36. package/src/client/app/index.tsx +422 -0
  37. package/src/client/app/preload.tsx +56 -0
  38. package/src/client/index.ts +40 -0
  39. package/src/client/ssr.tsx +50 -0
  40. package/src/client/theme/components/CodeBlock/CodeBlock.tsx +76 -0
  41. package/src/client/theme/components/CodeBlock/index.ts +1 -0
  42. package/src/client/theme/components/PackageManagerTabs/PackageManagerTabs.tsx +154 -0
  43. package/src/client/theme/components/PackageManagerTabs/index.ts +1 -0
  44. package/src/client/theme/components/PackageManagerTabs/pkg-tabs.css +64 -0
  45. package/src/client/theme/components/Playground/Playground.tsx +86 -0
  46. package/src/client/theme/components/Playground/index.ts +1 -0
  47. package/src/client/theme/components/Playground/playground.css +168 -0
  48. package/src/client/theme/components/Video/Video.tsx +84 -0
  49. package/src/client/theme/components/Video/index.ts +1 -0
  50. package/src/client/theme/components/Video/video.css +41 -0
  51. package/src/client/theme/components/mdx/Admonition.tsx +80 -0
  52. package/src/client/theme/components/mdx/Badge.tsx +31 -0
  53. package/src/client/theme/components/mdx/Button.tsx +50 -0
  54. package/src/client/theme/components/mdx/Card.tsx +80 -0
  55. package/src/client/theme/components/mdx/List.tsx +57 -0
  56. package/src/client/theme/components/mdx/Tabs.tsx +94 -0
  57. package/src/client/theme/components/mdx/index.ts +18 -0
  58. package/src/client/theme/components/mdx/mdx-components.css +405 -0
  59. package/src/client/theme/icons/bun.tsx +62 -0
  60. package/src/client/theme/icons/deno.tsx +20 -0
  61. package/src/client/theme/icons/discord.tsx +12 -0
  62. package/src/client/theme/icons/github.tsx +15 -0
  63. package/src/client/theme/icons/npm.tsx +13 -0
  64. package/src/client/theme/icons/pnpm.tsx +72 -0
  65. package/src/client/theme/icons/twitter.tsx +12 -0
  66. package/src/client/theme/styles/home.css +60 -0
  67. package/src/client/theme/styles/markdown.css +343 -0
  68. package/src/client/theme/styles/variables.css +162 -0
  69. package/src/client/theme/styles.css +38 -0
  70. package/src/client/theme/ui/BackgroundGradient/BackgroundGradient.tsx +10 -0
  71. package/src/client/theme/ui/BackgroundGradient/index.ts +1 -0
  72. package/src/client/theme/ui/Breadcrumbs/Breadcrumbs.tsx +68 -0
  73. package/src/client/theme/ui/Breadcrumbs/index.ts +1 -0
  74. package/src/client/theme/ui/Footer/footer.css +32 -0
  75. package/src/client/theme/ui/Head/Head.tsx +69 -0
  76. package/src/client/theme/ui/Head/index.ts +1 -0
  77. package/src/client/theme/ui/LanguageSwitcher/LanguageSwitcher.tsx +125 -0
  78. package/src/client/theme/ui/LanguageSwitcher/index.ts +1 -0
  79. package/src/client/theme/ui/LanguageSwitcher/language-switcher.css +98 -0
  80. package/src/client/theme/ui/Layout/Layout.tsx +213 -0
  81. package/src/client/theme/ui/Layout/base.css +76 -0
  82. package/src/client/theme/ui/Layout/index.ts +2 -0
  83. package/src/client/theme/ui/Layout/pagination.css +72 -0
  84. package/src/client/theme/ui/Layout/responsive.css +40 -0
  85. package/src/client/theme/ui/Link/Link.tsx +202 -0
  86. package/src/client/theme/ui/Link/index.ts +2 -0
  87. package/src/client/theme/ui/Loading/Loading.tsx +10 -0
  88. package/src/client/theme/ui/Loading/index.ts +1 -0
  89. package/src/client/theme/ui/Loading/loading.css +30 -0
  90. package/src/client/theme/ui/Navbar/GithubStars.tsx +27 -0
  91. package/src/client/theme/ui/Navbar/Navbar.tsx +145 -0
  92. package/src/client/theme/ui/Navbar/index.ts +2 -0
  93. package/src/client/theme/ui/Navbar/navbar.css +233 -0
  94. package/src/client/theme/ui/NotFound/NotFound.tsx +20 -0
  95. package/src/client/theme/ui/NotFound/index.ts +1 -0
  96. package/src/client/theme/ui/NotFound/not-found.css +64 -0
  97. package/src/client/theme/ui/OnThisPage/OnThisPage.tsx +192 -0
  98. package/src/client/theme/ui/OnThisPage/index.ts +1 -0
  99. package/src/client/theme/ui/OnThisPage/toc.css +132 -0
  100. package/src/client/theme/ui/PoweredBy/PoweredBy.tsx +18 -0
  101. package/src/client/theme/ui/PoweredBy/index.ts +1 -0
  102. package/src/client/theme/ui/PoweredBy/powered-by.css +76 -0
  103. package/src/client/theme/ui/SearchDialog/SearchDialog.tsx +199 -0
  104. package/src/client/theme/ui/SearchDialog/index.ts +1 -0
  105. package/src/client/theme/ui/SearchDialog/search.css +152 -0
  106. package/src/client/theme/ui/Sidebar/Sidebar.tsx +200 -0
  107. package/src/client/theme/ui/Sidebar/index.ts +1 -0
  108. package/src/client/theme/ui/Sidebar/sidebar.css +269 -0
  109. package/src/client/theme/ui/ThemeToggle/ThemeToggle.tsx +69 -0
  110. package/src/client/theme/ui/ThemeToggle/index.ts +1 -0
  111. package/src/client/theme/ui/VersionSwitcher/VersionSwitcher.tsx +136 -0
  112. package/src/client/theme/ui/VersionSwitcher/index.ts +1 -0
  113. package/src/client/utils.ts +26 -0
  114. package/src/node/cache.ts +94 -0
  115. package/src/node/cli/commands/config.ts +15 -0
  116. package/src/node/cli/commands/generate-css.ts +24 -0
  117. package/src/node/cli/constants.ts +70 -0
  118. package/src/node/cli/index.ts +22 -0
  119. package/src/node/config.ts +185 -0
  120. package/src/node/index.ts +21 -0
  121. package/src/node/mdx.ts +41 -0
  122. package/src/node/plugin/entry.ts +58 -0
  123. package/src/node/plugin/html.ts +55 -0
  124. package/src/node/plugin/index.ts +190 -0
  125. package/src/node/plugin/types.ts +11 -0
  126. package/src/node/routes/cache.ts +24 -0
  127. package/src/node/routes/index.ts +152 -0
  128. package/src/node/routes/parser.ts +127 -0
  129. package/src/node/routes/sorter.ts +42 -0
  130. package/src/node/routes/types.ts +49 -0
  131. package/src/node/ssg/index.ts +110 -0
  132. package/src/node/ssg/meta.ts +34 -0
  133. package/src/node/ssg/options.ts +13 -0
  134. package/src/node/ssg/sitemap.ts +54 -0
  135. package/src/node/utils.ts +134 -0
  136. package/tsconfig.json +20 -0
  137. package/tsup.config.ts +22 -0
@@ -0,0 +1,719 @@
1
+ import {
2
+ CONFIG_FILES,
3
+ init_config,
4
+ resolveConfig
5
+ } from "../chunk-X2TDGMTR.mjs";
6
+ import "../chunk-X6BYQHVC.mjs";
7
+
8
+ // src/node/plugin/index.ts
9
+ import { loadEnv } from "vite";
10
+
11
+ // src/node/routes/index.ts
12
+ import fastGlob from "fast-glob";
13
+
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, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
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
+ // src/node/routes/cache.ts
137
+ var docCache = new FileCache();
138
+ function invalidateRouteCache() {
139
+ docCache.invalidateAll();
140
+ }
141
+ function invalidateFile(filePath) {
142
+ docCache.invalidate(filePath);
143
+ }
144
+
145
+ // src/node/routes/parser.ts
146
+ import path from "path";
147
+ import GithubSlugger from "github-slugger";
148
+ function parseDocFile(file, docsDir, basePath, config) {
149
+ const { data, content } = parseFrontmatter(file);
150
+ const relativePath = normalizePath(path.relative(docsDir, file));
151
+ let parts = relativePath.split("/");
152
+ let locale;
153
+ let version;
154
+ if (config?.versions && parts.length > 0) {
155
+ const potentialVersion = parts[0];
156
+ if (config.versions.versions[potentialVersion]) {
157
+ version = potentialVersion;
158
+ parts = parts.slice(1);
159
+ }
160
+ }
161
+ if (config?.i18n && parts.length > 0) {
162
+ const potentialLocale = parts[0];
163
+ if (config.i18n.locales[potentialLocale]) {
164
+ locale = potentialLocale;
165
+ parts = parts.slice(1);
166
+ }
167
+ }
168
+ const cleanRelativePath = parts.join("/");
169
+ const cleanRoutePath = fileToRoutePath(cleanRelativePath || "index.md");
170
+ let finalPath = basePath;
171
+ if (version) {
172
+ finalPath += "/" + version;
173
+ }
174
+ if (locale) {
175
+ finalPath += "/" + locale;
176
+ }
177
+ finalPath += cleanRoutePath === "/" ? "" : cleanRoutePath;
178
+ if (!finalPath || finalPath === "") finalPath = "/";
179
+ const rawFileName = parts[parts.length - 1];
180
+ const cleanFileName = stripNumberPrefix(rawFileName);
181
+ const inferredTitle = stripNumberPrefix(
182
+ path.basename(file, path.extname(file))
183
+ );
184
+ const sidebarPosition = data.sidebarPosition ?? extractNumberPrefix(rawFileName);
185
+ const rawDirName = parts.length >= 2 ? parts[0] : void 0;
186
+ const cleanDirName = rawDirName ? stripNumberPrefix(rawDirName) : void 0;
187
+ const isGroupIndex = parts.length >= 2 && /^index\.mdx?$/.test(cleanFileName);
188
+ const headings = [];
189
+ const slugger = new GithubSlugger();
190
+ const headingsRegex = /^(#{2,4})\s+(.+)$/gm;
191
+ let match;
192
+ while ((match = headingsRegex.exec(content)) !== null) {
193
+ const level = match[1].length;
194
+ const text = match[2].replace(/\[([^\]]+)\]\([^\)]+\)/g, "$1").replace(/[_*`]/g, "").trim();
195
+ const id = slugger.slug(text);
196
+ headings.push({ level, text, id });
197
+ }
198
+ return {
199
+ route: {
200
+ path: finalPath,
201
+ componentPath: file,
202
+ filePath: relativePath,
203
+ title: data.title || inferredTitle,
204
+ description: data.description || "",
205
+ sidebarPosition,
206
+ headings,
207
+ locale,
208
+ version,
209
+ badge: data.badge
210
+ },
211
+ relativeDir: cleanDirName,
212
+ isGroupIndex,
213
+ groupMeta: isGroupIndex ? {
214
+ title: data.groupTitle || data.title || (cleanDirName ? capitalize(cleanDirName) : ""),
215
+ position: data.groupPosition ?? data.sidebarPosition ?? (rawDirName ? extractNumberPrefix(rawDirName) : void 0)
216
+ } : void 0,
217
+ inferredGroupPosition: rawDirName ? extractNumberPrefix(rawDirName) : void 0
218
+ };
219
+ }
220
+
221
+ // src/node/routes/sorter.ts
222
+ function sortRoutes(routes) {
223
+ return routes.sort((a, b) => {
224
+ if (!a.group && !b.group) return compareByPosition(a, b);
225
+ if (!a.group) return -1;
226
+ if (!b.group) return 1;
227
+ if (a.group !== b.group) {
228
+ return compareByGroupPosition(a, b);
229
+ }
230
+ return compareByPosition(a, b);
231
+ });
232
+ }
233
+ function compareByPosition(a, b) {
234
+ if (a.sidebarPosition !== void 0 && b.sidebarPosition !== void 0)
235
+ return a.sidebarPosition - b.sidebarPosition;
236
+ if (a.sidebarPosition !== void 0) return -1;
237
+ if (b.sidebarPosition !== void 0) return 1;
238
+ return a.title.localeCompare(b.title);
239
+ }
240
+ function compareByGroupPosition(a, b) {
241
+ if (a.groupPosition !== void 0 && b.groupPosition !== void 0)
242
+ return a.groupPosition - b.groupPosition;
243
+ if (a.groupPosition !== void 0) return -1;
244
+ if (b.groupPosition !== void 0) return 1;
245
+ return (a.groupTitle || a.group).localeCompare(b.groupTitle || b.group);
246
+ }
247
+
248
+ // src/node/routes/index.ts
249
+ async function generateRoutes(docsDir, config, basePath = "/docs") {
250
+ const files = await fastGlob(["**/*.md", "**/*.mdx"], {
251
+ cwd: docsDir,
252
+ absolute: true
253
+ });
254
+ docCache.pruneStale(new Set(files));
255
+ if (config?.i18n) {
256
+ docCache.invalidateAll();
257
+ }
258
+ const parsed = await Promise.all(
259
+ files.map(async (file) => {
260
+ const cached = docCache.get(file);
261
+ if (cached) return cached;
262
+ const result = parseDocFile(file, docsDir, basePath, config);
263
+ docCache.set(file, result);
264
+ return result;
265
+ })
266
+ );
267
+ const groupMeta = /* @__PURE__ */ new Map();
268
+ for (const p of parsed) {
269
+ if (p.relativeDir) {
270
+ if (!groupMeta.has(p.relativeDir)) {
271
+ groupMeta.set(p.relativeDir, {
272
+ title: capitalize(p.relativeDir),
273
+ position: p.inferredGroupPosition
274
+ });
275
+ } else {
276
+ const entry = groupMeta.get(p.relativeDir);
277
+ if (entry.position === void 0 && p.inferredGroupPosition !== void 0) {
278
+ entry.position = p.inferredGroupPosition;
279
+ }
280
+ }
281
+ }
282
+ if (p.isGroupIndex && p.relativeDir && p.groupMeta) {
283
+ const entry = groupMeta.get(p.relativeDir);
284
+ entry.title = p.groupMeta.title;
285
+ if (p.groupMeta.position !== void 0) {
286
+ entry.position = p.groupMeta.position;
287
+ }
288
+ }
289
+ }
290
+ const routes = parsed.map((p) => {
291
+ const dir = p.relativeDir;
292
+ const meta = dir ? groupMeta.get(dir) : void 0;
293
+ return {
294
+ ...p.route,
295
+ group: dir,
296
+ groupTitle: meta?.title || (dir ? capitalize(dir) : void 0),
297
+ groupPosition: meta?.position
298
+ };
299
+ });
300
+ if (config?.i18n) {
301
+ const defaultLocale = config.i18n.defaultLocale;
302
+ const allLocales = Object.keys(config.i18n.locales);
303
+ const fallbackRoutes = [];
304
+ const defaultRoutes = routes.filter(
305
+ (r) => (r.locale || defaultLocale) === defaultLocale
306
+ );
307
+ for (const locale of allLocales) {
308
+ if (locale === defaultLocale) continue;
309
+ const localeRoutePaths = new Set(
310
+ routes.filter((r) => r.locale === locale).map((r) => r.path)
311
+ );
312
+ for (const defRoute of defaultRoutes) {
313
+ let prefix = basePath;
314
+ if (defRoute.version) {
315
+ prefix += "/" + defRoute.version;
316
+ }
317
+ let pathAfterVersion = defRoute.path.substring(prefix.length);
318
+ if (pathAfterVersion.startsWith("/" + defaultLocale + "/")) {
319
+ pathAfterVersion = pathAfterVersion.substring(
320
+ defaultLocale.length + 1
321
+ );
322
+ } else if (pathAfterVersion === "/" + defaultLocale) {
323
+ pathAfterVersion = "/";
324
+ }
325
+ const targetPath = prefix + "/" + locale + (pathAfterVersion === "/" || pathAfterVersion === "" ? "" : pathAfterVersion);
326
+ if (!localeRoutePaths.has(targetPath)) {
327
+ fallbackRoutes.push({
328
+ ...defRoute,
329
+ path: targetPath,
330
+ locale
331
+ });
332
+ }
333
+ }
334
+ }
335
+ return sortRoutes([...routes, ...fallbackRoutes]);
336
+ }
337
+ return sortRoutes(routes);
338
+ }
339
+
340
+ // src/node/plugin/index.ts
341
+ init_config();
342
+ import { ViteImageOptimizer } from "vite-plugin-image-optimizer";
343
+
344
+ // src/node/ssg/index.ts
345
+ import fs2 from "fs";
346
+ import path2 from "path";
347
+ import { fileURLToPath } from "url";
348
+ import { createRequire } from "module";
349
+
350
+ // src/node/ssg/meta.ts
351
+ function replaceMetaTags(html, meta) {
352
+ return html.replace(/<title>.*?<\/title>/, `<title>${meta.title}</title>`).replace(
353
+ /(<meta name="description" content=")[^"]*(")/,
354
+ `$1${meta.description}$2`
355
+ ).replace(
356
+ /(<meta property="og:title" content=")[^"]*(")/,
357
+ `$1${meta.title}$2`
358
+ ).replace(
359
+ /(<meta property="og:description" content=")[^"]*(")/,
360
+ `$1${meta.description}$2`
361
+ ).replace(
362
+ /(<meta name="twitter:title" content=")[^"]*(")/,
363
+ `$1${meta.title}$2`
364
+ ).replace(
365
+ /(<meta name="twitter:description" content=")[^"]*(")/,
366
+ `$1${meta.description}$2`
367
+ );
368
+ }
369
+
370
+ // src/node/ssg/sitemap.ts
371
+ function generateSitemap(routePaths, config) {
372
+ const baseUrl = config?.siteUrl?.replace(/\/$/, "") || "https://example.com";
373
+ const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
374
+ const rootEntries = [{ url: "/", priority: "1.0", changefreq: "daily" }];
375
+ if (config?.i18n) {
376
+ const defaultLocale = config.i18n.defaultLocale;
377
+ for (const locale of Object.keys(config.i18n.locales)) {
378
+ if (locale !== defaultLocale) {
379
+ rootEntries.push({
380
+ url: `/${locale}/`,
381
+ priority: "1.0",
382
+ changefreq: "daily"
383
+ });
384
+ }
385
+ }
386
+ }
387
+ const entries = [
388
+ ...rootEntries,
389
+ ...routePaths.map((p) => ({
390
+ url: p,
391
+ priority: "0.8",
392
+ changefreq: "weekly"
393
+ }))
394
+ ];
395
+ return `<?xml version="1.0" encoding="UTF-8"?>
396
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
397
+ ${entries.map(
398
+ (e) => ` <url>
399
+ <loc>${baseUrl}${e.url}</loc>
400
+ <lastmod>${today}</lastmod>
401
+ <changefreq>${e.changefreq}</changefreq>
402
+ <priority>${e.priority}</priority>
403
+ </url>`
404
+ ).join("\n")}
405
+ </urlset>`;
406
+ }
407
+
408
+ // src/node/ssg/index.ts
409
+ var _filename = fileURLToPath(import.meta.url);
410
+ var _dirname = path2.dirname(_filename);
411
+ var _require = createRequire(import.meta.url);
412
+ async function generateStaticPages(options) {
413
+ const { docsDir, outDir, config } = options;
414
+ const routes = await generateRoutes(docsDir, config);
415
+ const siteTitle = config?.themeConfig?.title || "Boltdocs";
416
+ const siteDescription = config?.themeConfig?.description || "";
417
+ const ssrModulePath = path2.resolve(_dirname, "../client/ssr.js");
418
+ if (!fs2.existsSync(ssrModulePath)) {
419
+ console.error(
420
+ "[boltdocs] SSR module not found at",
421
+ ssrModulePath,
422
+ "- Did you build the core package?"
423
+ );
424
+ return;
425
+ }
426
+ const { render } = _require(ssrModulePath);
427
+ const templatePath = path2.join(outDir, "index.html");
428
+ if (!fs2.existsSync(templatePath)) {
429
+ console.warn("[boltdocs] No index.html found in outDir, skipping SSG.");
430
+ return;
431
+ }
432
+ const template = fs2.readFileSync(templatePath, "utf-8");
433
+ let homePageComp;
434
+ if (config?._homePagePath) {
435
+ try {
436
+ } catch (e) {
437
+ }
438
+ }
439
+ await Promise.all(
440
+ routes.map(async (route) => {
441
+ const pageTitle = `${route.title} | ${siteTitle}`;
442
+ const pageDescription = route.description || siteDescription;
443
+ const fakeModules = {};
444
+ fakeModules[route.componentPath] = { default: () => {
445
+ } };
446
+ try {
447
+ const appHtml = await render({
448
+ path: route.path,
449
+ routes,
450
+ config: config || {},
451
+ modules: fakeModules,
452
+ homePage: homePageComp
453
+ });
454
+ const html = replaceMetaTags(template, {
455
+ title: escapeHtml(pageTitle),
456
+ description: escapeHtml(pageDescription)
457
+ }).replace("<!--app-html-->", appHtml).replace(`<div id="root"></div>`, `<div id="root">${appHtml}</div>`);
458
+ const routeDir = path2.join(outDir, route.path);
459
+ await fs2.promises.mkdir(routeDir, { recursive: true });
460
+ await fs2.promises.writeFile(
461
+ path2.join(routeDir, "index.html"),
462
+ html,
463
+ "utf-8"
464
+ );
465
+ } catch (e) {
466
+ console.error(`[boltdocs] Error SSR rendering route ${route.path}:`, e);
467
+ }
468
+ })
469
+ );
470
+ const sitemap = generateSitemap(
471
+ routes.map((r) => r.path),
472
+ config
473
+ );
474
+ fs2.writeFileSync(path2.join(outDir, "sitemap.xml"), sitemap, "utf-8");
475
+ console.log(
476
+ `[boltdocs] Generated ${routes.length} static pages + sitemap.xml`
477
+ );
478
+ }
479
+
480
+ // src/node/plugin/index.ts
481
+ import path3 from "path";
482
+
483
+ // src/node/plugin/entry.ts
484
+ function generateEntryCode(options, config) {
485
+ const homeImport = options.homePage ? `import HomePage from '${normalizePath(options.homePage)}';` : "";
486
+ const homeOption = options.homePage ? "homePage: HomePage," : "";
487
+ const customCssImport = options.customCss ? `import '${normalizePath(options.customCss)}';` : "";
488
+ const pluginComponents = config?.plugins?.flatMap((p) => Object.entries(p.components || {})) || [];
489
+ const componentImports = pluginComponents.map(
490
+ ([
491
+ name,
492
+ path4
493
+ ]) => `import * as _comp_${name} from '${normalizePath(path4)}';
494
+ const ${name} = _comp_${name}.default || _comp_${name}['${name}'] || _comp_${name};`
495
+ ).join("\n");
496
+ const componentMap = pluginComponents.map(([name]) => name).join(", ");
497
+ return `
498
+ import { createBoltdocsApp as _createApp } from 'boltdocs/client';
499
+ import 'boltdocs/style.css';
500
+ ${customCssImport}
501
+ import _routes from 'virtual:boltdocs-routes';
502
+ import _config from 'virtual:boltdocs-config';
503
+ ${homeImport}
504
+ ${componentImports}
505
+
506
+ _createApp({
507
+ target: '#root',
508
+ routes: _routes,
509
+ config: _config,
510
+ modules: import.meta.glob('/docs/**/*.{md,mdx}'),
511
+ hot: import.meta.hot,
512
+ ${homeOption}
513
+ components: { ${componentMap} },
514
+ });
515
+ `;
516
+ }
517
+
518
+ // src/node/plugin/html.ts
519
+ function injectHtmlMeta(html, config) {
520
+ const title = config.themeConfig?.title || "Boltdocs";
521
+ const description = config.themeConfig?.description || "";
522
+ const seoTags = [
523
+ `<meta name="description" content="${description}">`,
524
+ `<meta property="og:title" content="${title}">`,
525
+ `<meta property="og:description" content="${description}">`,
526
+ `<meta property="og:type" content="website">`,
527
+ `<meta name="twitter:card" content="summary">`,
528
+ `<meta name="twitter:title" content="${title}">`,
529
+ `<meta name="twitter:description" content="${description}">`,
530
+ `<meta name="generator" content="Boltdocs">`
531
+ ].join("\n ");
532
+ const themeScript = `
533
+ <script>
534
+ (function() {
535
+ try {
536
+ var stored = localStorage.getItem("boltdocs-theme");
537
+ var theme = stored || (window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
538
+ if (theme === "light") {
539
+ document.documentElement.classList.add("theme-light");
540
+ document.documentElement.dataset.theme = "light";
541
+ } else {
542
+ document.documentElement.classList.remove("theme-light");
543
+ document.documentElement.dataset.theme = "dark";
544
+ }
545
+ } catch (e) {}
546
+ })();
547
+ </script>
548
+ `;
549
+ html = html.replace(/<title>.*?<\/title>/, `<title>${title}</title>`);
550
+ html = html.replace("</head>", ` ${seoTags}
551
+ ${themeScript} </head>`);
552
+ if (!html.includes("src/main")) {
553
+ html = html.replace(
554
+ "</body>",
555
+ ' <script type="module">import "virtual:boltdocs-entry";</script>\n </body>'
556
+ );
557
+ }
558
+ return html;
559
+ }
560
+
561
+ // src/node/plugin/index.ts
562
+ function boltdocsPlugin(options = {}, passedConfig) {
563
+ const docsDir = path3.resolve(process.cwd(), options.docsDir || "docs");
564
+ const normalizedDocsDir = normalizePath(docsDir);
565
+ let config = passedConfig;
566
+ let viteConfig;
567
+ let isBuild = false;
568
+ const extraVitePlugins = config?.plugins?.flatMap((p) => p.vitePlugins || []) || [];
569
+ return [
570
+ {
571
+ name: "vite-plugin-boltdocs",
572
+ enforce: "pre",
573
+ async config(userConfig, env) {
574
+ isBuild = env.command === "build";
575
+ const envDir = userConfig.envDir || process.cwd();
576
+ const envs = loadEnv(env.mode, envDir, "");
577
+ Object.assign(process.env, envs);
578
+ if (!config) {
579
+ config = await resolveConfig(docsDir);
580
+ }
581
+ if (!options.customCss && config.themeConfig?.customCss) {
582
+ options.customCss = config.themeConfig.customCss;
583
+ }
584
+ return {
585
+ optimizeDeps: { include: ["react", "react-dom"] }
586
+ };
587
+ },
588
+ configResolved(resolved) {
589
+ viteConfig = resolved;
590
+ },
591
+ configureServer(server) {
592
+ const configPaths = CONFIG_FILES.map(
593
+ (c) => path3.resolve(process.cwd(), c)
594
+ );
595
+ server.watcher.add(configPaths);
596
+ const handleFileEvent = async (file, type) => {
597
+ const normalized = normalizePath(file);
598
+ if (CONFIG_FILES.some((c) => normalized.endsWith(c))) {
599
+ server.restart();
600
+ return;
601
+ }
602
+ if (!normalized.startsWith(normalizedDocsDir) || !isDocFile(normalized))
603
+ return;
604
+ if (type === "add" || type === "unlink") {
605
+ invalidateRouteCache();
606
+ } else {
607
+ invalidateFile(file);
608
+ }
609
+ const newRoutes = await generateRoutes(docsDir, config);
610
+ const routesMod = server.moduleGraph.getModuleById(
611
+ "\0virtual:boltdocs-routes"
612
+ );
613
+ if (routesMod) server.moduleGraph.invalidateModule(routesMod);
614
+ server.ws.send({
615
+ type: "custom",
616
+ event: "boltdocs:routes-update",
617
+ data: newRoutes
618
+ });
619
+ };
620
+ server.watcher.on("add", (f) => handleFileEvent(f, "add"));
621
+ server.watcher.on("unlink", (f) => handleFileEvent(f, "unlink"));
622
+ server.watcher.on("change", (f) => handleFileEvent(f, "change"));
623
+ },
624
+ resolveId(id) {
625
+ if (id === "virtual:boltdocs-routes" || id === "virtual:boltdocs-config" || id === "virtual:boltdocs-entry") {
626
+ return "\0" + id;
627
+ }
628
+ },
629
+ async load(id) {
630
+ if (id === "\0virtual:boltdocs-routes") {
631
+ const routes = await generateRoutes(docsDir, config);
632
+ return `export default ${JSON.stringify(routes, null, 2)};`;
633
+ }
634
+ if (id === "\0virtual:boltdocs-config") {
635
+ const clientConfig = {
636
+ themeConfig: config?.themeConfig,
637
+ i18n: config?.i18n,
638
+ versions: config?.versions,
639
+ siteUrl: config?.siteUrl
640
+ };
641
+ return `export default ${JSON.stringify(clientConfig, null, 2)};`;
642
+ }
643
+ if (id === "\0virtual:boltdocs-entry") {
644
+ const code = generateEntryCode(options, config);
645
+ return code;
646
+ }
647
+ },
648
+ transformIndexHtml: {
649
+ order: "pre",
650
+ handler(html) {
651
+ return injectHtmlMeta(html, config);
652
+ }
653
+ },
654
+ async closeBundle() {
655
+ if (!isBuild) return;
656
+ const outDir = viteConfig?.build?.outDir ? path3.resolve(viteConfig.root, viteConfig.build.outDir) : path3.resolve(process.cwd(), "dist");
657
+ await generateStaticPages({ docsDir, outDir, config });
658
+ }
659
+ },
660
+ ViteImageOptimizer({
661
+ includePublic: true,
662
+ png: { quality: 80 },
663
+ jpeg: { quality: 80 },
664
+ jpg: { quality: 80 },
665
+ webp: { quality: 80 },
666
+ avif: { quality: 80 },
667
+ svg: {
668
+ multipass: true,
669
+ plugins: [
670
+ {
671
+ name: "preset-default",
672
+ params: { overrides: { removeViewBox: false } }
673
+ }
674
+ ]
675
+ }
676
+ }),
677
+ ...extraVitePlugins.filter((p) => !!p)
678
+ ];
679
+ }
680
+
681
+ // src/node/mdx.ts
682
+ import mdxPlugin from "@mdx-js/rollup";
683
+ import remarkGfm from "remark-gfm";
684
+ import remarkFrontmatter from "remark-frontmatter";
685
+ import rehypeSlug from "rehype-slug";
686
+ import rehypePrettyCode from "rehype-pretty-code";
687
+ function boltdocsMdxPlugin(config) {
688
+ const extraRemarkPlugins = config?.plugins?.flatMap((p) => p.remarkPlugins || []) || [];
689
+ const extraRehypePlugins = config?.plugins?.flatMap((p) => p.rehypePlugins || []) || [];
690
+ return mdxPlugin({
691
+ remarkPlugins: [remarkGfm, remarkFrontmatter, ...extraRemarkPlugins],
692
+ rehypePlugins: [
693
+ rehypeSlug,
694
+ ...extraRehypePlugins,
695
+ [
696
+ rehypePrettyCode,
697
+ {
698
+ theme: "one-dark-pro",
699
+ keepBackground: false
700
+ }
701
+ ]
702
+ ],
703
+ // Provide React as default for JSX
704
+ jsxRuntime: "automatic",
705
+ providerImportSource: "@mdx-js/react"
706
+ });
707
+ }
708
+
709
+ // src/node/index.ts
710
+ init_config();
711
+ async function boltdocs(options) {
712
+ const docsDir = options?.docsDir || "docs";
713
+ const config = await resolveConfig(docsDir);
714
+ return [...boltdocsPlugin(options, config), boltdocsMdxPlugin(config)];
715
+ }
716
+ export {
717
+ boltdocs as default,
718
+ generateStaticPages
719
+ };