boltdocs 1.10.2 → 2.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 (250) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +21 -0
  3. package/dist/cache-7G6D532T.mjs +1 -0
  4. package/dist/chunk-A4HQPEPU.mjs +1 -0
  5. package/dist/chunk-BA5NH5HU.mjs +1 -0
  6. package/dist/chunk-BQCD3DWG.mjs +1 -0
  7. package/dist/chunk-H63UMKYF.mjs +1 -0
  8. package/dist/chunk-IWHRQHS7.mjs +1 -0
  9. package/dist/chunk-JZXLCA2E.mjs +1 -0
  10. package/dist/chunk-MFU7Q6WF.mjs +1 -0
  11. package/dist/chunk-QYPNX5UN.mjs +1 -0
  12. package/dist/chunk-XEAPSFMB.mjs +1 -0
  13. package/dist/client/components/mdx/index.d.mts +209 -0
  14. package/dist/client/components/mdx/index.d.ts +209 -0
  15. package/dist/client/components/mdx/index.js +1 -0
  16. package/dist/client/components/mdx/index.mjs +1 -0
  17. package/dist/client/hooks/index.d.mts +133 -0
  18. package/dist/client/hooks/index.d.ts +133 -0
  19. package/dist/client/hooks/index.js +1 -0
  20. package/dist/client/hooks/index.mjs +1 -0
  21. package/dist/client/index.d.mts +138 -298
  22. package/dist/client/index.d.ts +138 -298
  23. package/dist/client/index.js +1 -3630
  24. package/dist/client/index.mjs +1 -697
  25. package/dist/client/ssr.d.mts +7 -3
  26. package/dist/client/ssr.d.ts +7 -3
  27. package/dist/client/ssr.js +1 -2928
  28. package/dist/client/ssr.mjs +1 -33
  29. package/dist/{config-BsFQ-ErD.d.ts → config-CX4l-ZNp.d.mts} +42 -35
  30. package/dist/{config-BsFQ-ErD.d.mts → config-CX4l-ZNp.d.ts} +42 -35
  31. package/dist/node/index.d.mts +2 -4
  32. package/dist/node/index.d.ts +2 -4
  33. package/dist/node/index.js +31 -1161
  34. package/dist/node/index.mjs +31 -736
  35. package/dist/search-dialog-EB3N4TYM.mjs +1 -0
  36. package/dist/types-BuZWFT7r.d.ts +159 -0
  37. package/dist/types-CvT-SGbK.d.mts +159 -0
  38. package/dist/use-routes-5bAtAAYX.d.mts +30 -0
  39. package/dist/use-routes-BefRXY3v.d.ts +30 -0
  40. package/package.json +34 -12
  41. package/src/client/app/config-context.tsx +18 -0
  42. package/src/client/app/docs-layout.tsx +14 -0
  43. package/src/client/app/index.tsx +137 -262
  44. package/src/client/app/mdx-component.tsx +52 -0
  45. package/src/client/app/mdx-components-context.tsx +23 -0
  46. package/src/client/app/mdx-page.tsx +20 -0
  47. package/src/client/app/preload.tsx +38 -30
  48. package/src/client/app/router.tsx +30 -0
  49. package/src/client/app/scroll-handler.tsx +40 -0
  50. package/src/client/app/theme-context.tsx +75 -0
  51. package/src/client/components/default-layout.tsx +80 -0
  52. package/src/client/components/docs-layout.tsx +105 -0
  53. package/src/client/components/icons-dev.tsx +74 -0
  54. package/src/client/components/mdx/admonition.tsx +107 -0
  55. package/src/client/components/mdx/badge.tsx +41 -0
  56. package/src/client/components/mdx/button.tsx +35 -0
  57. package/src/client/components/mdx/card.tsx +124 -0
  58. package/src/client/components/mdx/code-block.tsx +119 -0
  59. package/src/client/components/mdx/component-preview.tsx +47 -0
  60. package/src/client/components/mdx/component-props.tsx +83 -0
  61. package/src/client/components/mdx/field.tsx +66 -0
  62. package/src/client/components/mdx/file-tree.tsx +287 -0
  63. package/src/client/components/mdx/hooks/use-code-block.ts +56 -0
  64. package/src/client/components/mdx/hooks/use-component-preview.ts +16 -0
  65. package/src/client/components/mdx/hooks/useTable.ts +74 -0
  66. package/src/client/components/mdx/hooks/useTabs.ts +68 -0
  67. package/src/client/components/mdx/image.tsx +23 -0
  68. package/src/client/components/mdx/index.ts +53 -0
  69. package/src/client/components/mdx/link.tsx +38 -0
  70. package/src/client/components/mdx/list.tsx +192 -0
  71. package/src/client/components/mdx/table.tsx +156 -0
  72. package/src/client/components/mdx/tabs.tsx +135 -0
  73. package/src/client/components/mdx/video.tsx +68 -0
  74. package/src/client/components/primitives/breadcrumbs.tsx +79 -0
  75. package/src/client/components/primitives/button-group.tsx +54 -0
  76. package/src/client/components/primitives/button.tsx +145 -0
  77. package/src/client/components/primitives/helpers/observer.ts +120 -0
  78. package/src/client/components/primitives/index.ts +17 -0
  79. package/src/client/components/primitives/link.tsx +122 -0
  80. package/src/client/components/primitives/menu.tsx +159 -0
  81. package/src/client/components/primitives/navbar.tsx +359 -0
  82. package/src/client/components/primitives/navigation-menu.tsx +116 -0
  83. package/src/client/components/primitives/on-this-page.tsx +461 -0
  84. package/src/client/components/primitives/page-nav.tsx +87 -0
  85. package/src/client/components/primitives/popover.tsx +47 -0
  86. package/src/client/components/primitives/search-dialog.tsx +183 -0
  87. package/src/client/components/primitives/sidebar.tsx +154 -0
  88. package/src/client/components/primitives/tabs.tsx +90 -0
  89. package/src/client/components/primitives/tooltip.tsx +83 -0
  90. package/src/client/components/primitives/types.ts +11 -0
  91. package/src/client/components/ui-base/breadcrumbs.tsx +42 -0
  92. package/src/client/components/ui-base/copy-markdown.tsx +112 -0
  93. package/src/client/components/ui-base/error-boundary.tsx +52 -0
  94. package/src/client/components/ui-base/github-stars.tsx +27 -0
  95. package/src/client/components/ui-base/head.tsx +69 -0
  96. package/src/client/components/ui-base/loading.tsx +87 -0
  97. package/src/client/components/ui-base/navbar.tsx +138 -0
  98. package/src/client/components/ui-base/not-found.tsx +24 -0
  99. package/src/client/components/ui-base/on-this-page.tsx +152 -0
  100. package/src/client/components/ui-base/page-nav.tsx +39 -0
  101. package/src/client/components/ui-base/powered-by.tsx +19 -0
  102. package/src/client/components/ui-base/progress-bar.tsx +67 -0
  103. package/src/client/components/ui-base/search-dialog.tsx +82 -0
  104. package/src/client/components/ui-base/sidebar.tsx +104 -0
  105. package/src/client/components/ui-base/tabs.tsx +65 -0
  106. package/src/client/components/ui-base/theme-toggle.tsx +32 -0
  107. package/src/client/hooks/index.ts +12 -0
  108. package/src/client/hooks/use-breadcrumbs.ts +22 -0
  109. package/src/client/hooks/use-i18n.ts +84 -0
  110. package/src/client/hooks/use-localized-to.ts +95 -0
  111. package/src/client/hooks/use-location.ts +5 -0
  112. package/src/client/hooks/use-navbar.ts +60 -0
  113. package/src/client/hooks/use-onthispage.ts +23 -0
  114. package/src/client/hooks/use-page-nav.ts +22 -0
  115. package/src/client/hooks/use-routes.ts +72 -0
  116. package/src/client/hooks/use-search.ts +71 -0
  117. package/src/client/hooks/use-sidebar.ts +49 -0
  118. package/src/client/hooks/use-tabs.ts +43 -0
  119. package/src/client/hooks/use-version.ts +78 -0
  120. package/src/client/index.ts +55 -17
  121. package/src/client/integrations/codesandbox.ts +179 -0
  122. package/src/client/ssr.tsx +27 -16
  123. package/src/client/theme/neutral.css +360 -0
  124. package/src/client/types.ts +131 -27
  125. package/src/client/utils/cn.ts +6 -0
  126. package/src/client/utils/copy-clipboard.ts +22 -0
  127. package/src/client/utils/get-base-file-path.ts +21 -0
  128. package/src/client/utils/github.ts +121 -0
  129. package/src/client/utils/use-on-change.ts +15 -0
  130. package/src/client/virtual.d.ts +24 -0
  131. package/src/node/cache.ts +156 -156
  132. package/src/node/config.ts +159 -103
  133. package/src/node/index.ts +13 -13
  134. package/src/node/mdx.ts +213 -61
  135. package/src/node/plugin/entry.ts +29 -18
  136. package/src/node/plugin/html.ts +11 -11
  137. package/src/node/plugin/index.ts +161 -84
  138. package/src/node/plugin/types.ts +2 -4
  139. package/src/node/routes/cache.ts +6 -6
  140. package/src/node/routes/index.ts +206 -113
  141. package/src/node/routes/parser.ts +102 -82
  142. package/src/node/routes/sorter.ts +15 -15
  143. package/src/node/routes/types.ts +24 -24
  144. package/src/node/ssg/index.ts +73 -47
  145. package/src/node/ssg/meta.ts +4 -4
  146. package/src/node/ssg/options.ts +5 -5
  147. package/src/node/ssg/sitemap.ts +14 -14
  148. package/src/node/utils.ts +54 -31
  149. package/tsconfig.json +25 -20
  150. package/tsup.config.ts +23 -14
  151. package/dist/PackageManagerTabs-NVT7G625.mjs +0 -99
  152. package/dist/SearchDialog-AGVF6JBO.mjs +0 -194
  153. package/dist/SearchDialog-YPDOM7Q6.css +0 -2847
  154. package/dist/Video-KNTY5BNO.mjs +0 -6
  155. package/dist/cache-KNL5B4EE.mjs +0 -12
  156. package/dist/chunk-7SFUJWTB.mjs +0 -211
  157. package/dist/chunk-FFBNU6IJ.mjs +0 -386
  158. package/dist/chunk-FMTOYQLO.mjs +0 -37
  159. package/dist/chunk-TKLQWU7H.mjs +0 -1920
  160. package/dist/chunk-Z7JHYNAS.mjs +0 -57
  161. package/dist/client/index.css +0 -2847
  162. package/dist/client/ssr.css +0 -2847
  163. package/dist/types-Dj-bfnC3.d.mts +0 -74
  164. package/dist/types-Dj-bfnC3.d.ts +0 -74
  165. package/src/client/theme/components/CodeBlock/CodeBlock.tsx +0 -61
  166. package/src/client/theme/components/CodeBlock/index.ts +0 -1
  167. package/src/client/theme/components/PackageManagerTabs/PackageManagerTabs.tsx +0 -131
  168. package/src/client/theme/components/PackageManagerTabs/index.ts +0 -1
  169. package/src/client/theme/components/PackageManagerTabs/pkg-tabs.css +0 -64
  170. package/src/client/theme/components/Playground/Playground.tsx +0 -180
  171. package/src/client/theme/components/Playground/index.ts +0 -1
  172. package/src/client/theme/components/Playground/playground.css +0 -238
  173. package/src/client/theme/components/Video/Video.tsx +0 -84
  174. package/src/client/theme/components/Video/index.ts +0 -1
  175. package/src/client/theme/components/Video/video.css +0 -41
  176. package/src/client/theme/components/mdx/Admonition.tsx +0 -80
  177. package/src/client/theme/components/mdx/Badge.tsx +0 -31
  178. package/src/client/theme/components/mdx/Button.tsx +0 -50
  179. package/src/client/theme/components/mdx/Card.tsx +0 -80
  180. package/src/client/theme/components/mdx/Field.tsx +0 -60
  181. package/src/client/theme/components/mdx/FileTree.tsx +0 -229
  182. package/src/client/theme/components/mdx/List.tsx +0 -57
  183. package/src/client/theme/components/mdx/Table.tsx +0 -151
  184. package/src/client/theme/components/mdx/Tabs.tsx +0 -123
  185. package/src/client/theme/components/mdx/index.ts +0 -27
  186. package/src/client/theme/components/mdx/mdx-components.css +0 -764
  187. package/src/client/theme/icons/bun.tsx +0 -62
  188. package/src/client/theme/icons/deno.tsx +0 -20
  189. package/src/client/theme/icons/discord.tsx +0 -12
  190. package/src/client/theme/icons/github.tsx +0 -15
  191. package/src/client/theme/icons/npm.tsx +0 -13
  192. package/src/client/theme/icons/pnpm.tsx +0 -72
  193. package/src/client/theme/icons/twitter.tsx +0 -12
  194. package/src/client/theme/styles/markdown.css +0 -394
  195. package/src/client/theme/styles/variables.css +0 -175
  196. package/src/client/theme/styles.css +0 -39
  197. package/src/client/theme/ui/Breadcrumbs/Breadcrumbs.tsx +0 -68
  198. package/src/client/theme/ui/Breadcrumbs/index.ts +0 -1
  199. package/src/client/theme/ui/CopyMarkdown/CopyMarkdown.tsx +0 -82
  200. package/src/client/theme/ui/CopyMarkdown/copy-markdown.css +0 -112
  201. package/src/client/theme/ui/CopyMarkdown/index.ts +0 -1
  202. package/src/client/theme/ui/ErrorBoundary/ErrorBoundary.tsx +0 -50
  203. package/src/client/theme/ui/ErrorBoundary/error-boundary.css +0 -55
  204. package/src/client/theme/ui/ErrorBoundary/index.ts +0 -1
  205. package/src/client/theme/ui/Footer/footer.css +0 -32
  206. package/src/client/theme/ui/Head/Head.tsx +0 -69
  207. package/src/client/theme/ui/Head/index.ts +0 -1
  208. package/src/client/theme/ui/LanguageSwitcher/LanguageSwitcher.tsx +0 -125
  209. package/src/client/theme/ui/LanguageSwitcher/index.ts +0 -1
  210. package/src/client/theme/ui/LanguageSwitcher/language-switcher.css +0 -98
  211. package/src/client/theme/ui/Layout/Layout.tsx +0 -203
  212. package/src/client/theme/ui/Layout/base.css +0 -106
  213. package/src/client/theme/ui/Layout/index.ts +0 -2
  214. package/src/client/theme/ui/Layout/pagination.css +0 -72
  215. package/src/client/theme/ui/Layout/responsive.css +0 -47
  216. package/src/client/theme/ui/Link/Link.tsx +0 -392
  217. package/src/client/theme/ui/Link/LinkPreview.tsx +0 -59
  218. package/src/client/theme/ui/Link/index.ts +0 -2
  219. package/src/client/theme/ui/Link/link-preview.css +0 -48
  220. package/src/client/theme/ui/Loading/Loading.tsx +0 -10
  221. package/src/client/theme/ui/Loading/index.ts +0 -1
  222. package/src/client/theme/ui/Loading/loading.css +0 -30
  223. package/src/client/theme/ui/Navbar/GithubStars.tsx +0 -27
  224. package/src/client/theme/ui/Navbar/Navbar.tsx +0 -193
  225. package/src/client/theme/ui/Navbar/Tabs.tsx +0 -99
  226. package/src/client/theme/ui/Navbar/index.ts +0 -2
  227. package/src/client/theme/ui/Navbar/navbar.css +0 -347
  228. package/src/client/theme/ui/NotFound/NotFound.tsx +0 -19
  229. package/src/client/theme/ui/NotFound/index.ts +0 -1
  230. package/src/client/theme/ui/NotFound/not-found.css +0 -64
  231. package/src/client/theme/ui/OnThisPage/OnThisPage.tsx +0 -244
  232. package/src/client/theme/ui/OnThisPage/index.ts +0 -1
  233. package/src/client/theme/ui/OnThisPage/toc.css +0 -152
  234. package/src/client/theme/ui/PoweredBy/PoweredBy.tsx +0 -18
  235. package/src/client/theme/ui/PoweredBy/index.ts +0 -1
  236. package/src/client/theme/ui/PoweredBy/powered-by.css +0 -76
  237. package/src/client/theme/ui/ProgressBar/ProgressBar.css +0 -17
  238. package/src/client/theme/ui/ProgressBar/ProgressBar.tsx +0 -51
  239. package/src/client/theme/ui/ProgressBar/index.ts +0 -1
  240. package/src/client/theme/ui/SearchDialog/SearchDialog.tsx +0 -209
  241. package/src/client/theme/ui/SearchDialog/index.ts +0 -1
  242. package/src/client/theme/ui/SearchDialog/search.css +0 -152
  243. package/src/client/theme/ui/Sidebar/Sidebar.tsx +0 -244
  244. package/src/client/theme/ui/Sidebar/index.ts +0 -1
  245. package/src/client/theme/ui/Sidebar/sidebar.css +0 -230
  246. package/src/client/theme/ui/ThemeToggle/ThemeToggle.tsx +0 -69
  247. package/src/client/theme/ui/ThemeToggle/index.ts +0 -1
  248. package/src/client/theme/ui/VersionSwitcher/VersionSwitcher.tsx +0 -136
  249. package/src/client/theme/ui/VersionSwitcher/index.ts +0 -1
  250. package/src/client/utils.ts +0 -49
@@ -1,524 +1,37 @@
1
- import {
2
- FileCache,
3
- TransformCache,
4
- capitalize,
5
- escapeHtml,
6
- escapeXml,
7
- extractNumberPrefix,
8
- fileToRoutePath,
9
- isDocFile,
10
- normalizePath,
11
- parseFrontmatter,
12
- stripNumberPrefix
13
- } from "../chunk-FFBNU6IJ.mjs";
14
-
15
- // src/node/plugin/index.ts
16
- import { loadEnv } from "vite";
17
-
18
- // src/node/routes/index.ts
19
- import fastGlob from "fast-glob";
20
-
21
- // src/node/routes/cache.ts
22
- var docCache = new FileCache({ name: "routes" });
23
- function invalidateRouteCache() {
24
- docCache.invalidateAll();
25
- }
26
- function invalidateFile(filePath) {
27
- docCache.invalidate(filePath);
28
- }
29
-
30
- // src/node/routes/parser.ts
31
- import path from "path";
32
- import GithubSlugger from "github-slugger";
33
- function parseDocFile(file, docsDir, basePath, config) {
34
- const decodedFile = decodeURIComponent(file);
35
- const absoluteFile = path.resolve(decodedFile);
36
- const absoluteDocsDir = path.resolve(docsDir);
37
- const relativePath = normalizePath(
38
- path.relative(absoluteDocsDir, absoluteFile)
39
- );
40
- if (relativePath.startsWith("../") || relativePath === ".." || absoluteFile.includes("\0")) {
41
- throw new Error(
42
- `Security breach: File is outside of docs directory or contains null bytes: ${file}`
43
- );
44
- }
45
- const { data, content } = parseFrontmatter(file);
46
- let parts = relativePath.split("/");
47
- let locale;
48
- let version;
49
- if (config?.versions && parts.length > 0) {
50
- const potentialVersion = parts[0];
51
- if (config.versions.versions[potentialVersion]) {
52
- version = potentialVersion;
53
- parts = parts.slice(1);
54
- }
55
- }
56
- if (config?.i18n && parts.length > 0) {
57
- const potentialLocale = parts[0];
58
- if (config.i18n.locales[potentialLocale]) {
59
- locale = potentialLocale;
60
- parts = parts.slice(1);
61
- }
62
- }
63
- let inferredTab;
64
- if (parts.length > 0) {
65
- const tabMatch = parts[0].match(/^\((.+)\)$/);
66
- if (tabMatch) {
67
- inferredTab = tabMatch[1].toLowerCase();
68
- parts = parts.slice(1);
69
- }
70
- }
71
- const cleanRelativePath = parts.join("/");
72
- let cleanRoutePath;
73
- if (data.permalink) {
74
- cleanRoutePath = data.permalink.startsWith("/") ? data.permalink : `/${data.permalink}`;
75
- } else {
76
- cleanRoutePath = fileToRoutePath(cleanRelativePath || "index.md");
77
- }
78
- let finalPath = basePath;
79
- if (version) {
80
- finalPath += "/" + version;
81
- }
82
- if (locale) {
83
- finalPath += "/" + locale;
84
- }
85
- finalPath += cleanRoutePath === "/" ? "" : cleanRoutePath;
86
- if (!finalPath || finalPath === "") finalPath = "/";
87
- const rawFileName = parts[parts.length - 1];
88
- const cleanFileName = stripNumberPrefix(rawFileName);
89
- const inferredTitle = stripNumberPrefix(
90
- path.basename(file, path.extname(file))
91
- );
92
- const sidebarPosition = data.sidebarPosition ?? extractNumberPrefix(rawFileName);
93
- const rawDirName = parts.length >= 2 ? parts[0] : void 0;
94
- const cleanDirName = rawDirName ? stripNumberPrefix(rawDirName) : void 0;
95
- const isGroupIndex = parts.length >= 2 && /^index\.mdx?$/.test(cleanFileName);
96
- const headings = [];
97
- const slugger = new GithubSlugger();
98
- const headingsRegex = /^(#{2,4})\s+(.+)$/gm;
99
- let match;
100
- while ((match = headingsRegex.exec(content)) !== null) {
101
- const level = match[1].length;
102
- const text = match[2].replace(/\[([^\]]+)\]\([^\)]+\)/g, "$1").replace(/[_*`]/g, "").trim();
103
- const id = slugger.slug(text);
104
- headings.push({ level, text, id });
105
- }
106
- const sanitizedTitle = data.title ? data.title : inferredTitle;
107
- let sanitizedDescription = data.description ? data.description : "";
108
- if (!sanitizedDescription && content) {
109
- const summary = content.replace(/^#+.*$/gm, "").replace(/\[([^\]]+)\]\([^\)]+\)/g, "$1").replace(/[_*`]/g, "").replace(/\n+/g, " ").trim().slice(0, 160);
110
- sanitizedDescription = summary;
111
- }
112
- const sanitizedBadge = data.badge ? data.badge : void 0;
113
- const icon = data.icon ? String(data.icon) : void 0;
114
- const plainText = content.replace(/^#+.*$/gm, "").replace(/\[([^\]]+)\]\([^\)]+\)/g, "$1").replace(/<[^>]+>/g, "").replace(/\{[^\}]+\}/g, "").replace(/[_*`]/g, "").replace(/\n+/g, " ").trim();
115
- return {
116
- route: {
117
- path: finalPath,
118
- componentPath: file,
119
- filePath: relativePath,
120
- title: sanitizedTitle,
121
- description: sanitizedDescription,
122
- sidebarPosition,
123
- headings,
124
- locale,
125
- version,
126
- badge: sanitizedBadge,
127
- icon,
128
- tab: inferredTab,
129
- _content: plainText,
130
- _rawContent: content
131
- },
132
- relativeDir: cleanDirName,
133
- isGroupIndex,
134
- inferredTab,
135
- groupMeta: isGroupIndex ? {
136
- title: data.groupTitle || data.title || (cleanDirName ? capitalize(cleanDirName) : ""),
137
- position: data.groupPosition ?? data.sidebarPosition ?? (rawDirName ? extractNumberPrefix(rawDirName) : void 0),
138
- icon
139
- } : void 0,
140
- inferredGroupPosition: rawDirName ? extractNumberPrefix(rawDirName) : void 0
141
- };
142
- }
143
-
144
- // src/node/routes/sorter.ts
145
- function sortRoutes(routes) {
146
- return routes.sort((a, b) => {
147
- if (!a.group && !b.group) return compareByPosition(a, b);
148
- if (!a.group) return -1;
149
- if (!b.group) return 1;
150
- if (a.group !== b.group) {
151
- return compareByGroupPosition(a, b);
152
- }
153
- return compareByPosition(a, b);
154
- });
155
- }
156
- function compareByPosition(a, b) {
157
- if (a.sidebarPosition !== void 0 && b.sidebarPosition !== void 0)
158
- return a.sidebarPosition - b.sidebarPosition;
159
- if (a.sidebarPosition !== void 0) return -1;
160
- if (b.sidebarPosition !== void 0) return 1;
161
- return a.title.localeCompare(b.title);
162
- }
163
- function compareByGroupPosition(a, b) {
164
- if (a.groupPosition !== void 0 && b.groupPosition !== void 0)
165
- return a.groupPosition - b.groupPosition;
166
- if (a.groupPosition !== void 0) return -1;
167
- if (b.groupPosition !== void 0) return 1;
168
- return (a.groupTitle || a.group).localeCompare(b.groupTitle || b.group);
169
- }
170
-
171
- // src/node/routes/index.ts
172
- async function generateRoutes(docsDir, config, basePath = "/docs") {
173
- docCache.load();
174
- docCache.invalidateAll();
175
- const files = await fastGlob(["**/*.md", "**/*.mdx"], {
176
- cwd: docsDir,
177
- absolute: true
178
- });
179
- docCache.pruneStale(new Set(files));
180
- if (config?.i18n) {
181
- docCache.invalidateAll();
182
- }
183
- let cacheHits = 0;
184
- const parsed = await Promise.all(
185
- files.map(async (file) => {
186
- const cached = docCache.get(file);
187
- if (cached) {
188
- cacheHits++;
189
- return cached;
190
- }
191
- const result = parseDocFile(file, docsDir, basePath, config);
192
- docCache.set(file, result);
193
- return result;
194
- })
195
- );
196
- if (files.length > 0) {
197
- console.log(
198
- `[boltdocs] Routes generated: ${files.length} files (${cacheHits} from cache, ${files.length - cacheHits} parsed)`
199
- );
200
- }
201
- docCache.save();
202
- const groupMeta = /* @__PURE__ */ new Map();
203
- for (const p of parsed) {
204
- if (p.relativeDir) {
205
- if (!groupMeta.has(p.relativeDir)) {
206
- groupMeta.set(p.relativeDir, {
207
- title: capitalize(p.relativeDir),
208
- position: p.inferredGroupPosition,
209
- icon: p.route.icon
210
- });
211
- } else {
212
- const entry = groupMeta.get(p.relativeDir);
213
- if (entry.position === void 0 && p.inferredGroupPosition !== void 0) {
214
- entry.position = p.inferredGroupPosition;
215
- }
216
- if (!entry.icon && p.route.icon) {
217
- entry.icon = p.route.icon;
218
- }
219
- }
220
- }
221
- if (p.isGroupIndex && p.relativeDir && p.groupMeta) {
222
- const entry = groupMeta.get(p.relativeDir);
223
- entry.title = p.groupMeta.title;
224
- if (p.groupMeta.position !== void 0) {
225
- entry.position = p.groupMeta.position;
226
- }
227
- if (p.groupMeta.icon) {
228
- entry.icon = p.groupMeta.icon;
229
- }
230
- }
231
- }
232
- const routes = parsed.map((p) => {
233
- const dir = p.relativeDir;
234
- const meta = dir ? groupMeta.get(dir) : void 0;
235
- return {
236
- ...p.route,
237
- group: dir,
238
- groupTitle: meta?.title || (dir ? capitalize(dir) : void 0),
239
- groupPosition: meta?.position,
240
- groupIcon: meta?.icon
241
- };
242
- });
243
- if (config?.i18n) {
244
- const defaultLocale = config.i18n.defaultLocale;
245
- const allLocales = Object.keys(config.i18n.locales);
246
- const fallbackRoutes = [];
247
- const defaultRoutes = routes.filter(
248
- (r) => (r.locale || defaultLocale) === defaultLocale
249
- );
250
- for (const locale of allLocales) {
251
- if (locale === defaultLocale) continue;
252
- const localeRoutePaths = new Set(
253
- routes.filter((r) => r.locale === locale).map((r) => r.path)
254
- );
255
- for (const defRoute of defaultRoutes) {
256
- let prefix = basePath;
257
- if (defRoute.version) {
258
- prefix += "/" + defRoute.version;
259
- }
260
- let pathAfterVersion = defRoute.path.substring(prefix.length);
261
- if (pathAfterVersion.startsWith("/" + defaultLocale + "/")) {
262
- pathAfterVersion = pathAfterVersion.substring(
263
- defaultLocale.length + 1
264
- );
265
- } else if (pathAfterVersion === "/" + defaultLocale) {
266
- pathAfterVersion = "/";
267
- }
268
- const targetPath = prefix + "/" + locale + (pathAfterVersion === "/" || pathAfterVersion === "" ? "" : pathAfterVersion);
269
- if (!localeRoutePaths.has(targetPath)) {
270
- fallbackRoutes.push({
271
- ...defRoute,
272
- path: targetPath,
273
- locale
274
- });
275
- }
276
- }
277
- }
278
- return sortRoutes([...routes, ...fallbackRoutes]);
279
- }
280
- return sortRoutes(routes);
281
- }
282
-
283
- // src/node/plugin/index.ts
284
- import { ViteImageOptimizer } from "vite-plugin-image-optimizer";
285
-
286
- // src/node/config.ts
287
- import path2 from "path";
288
- import { pathToFileURL } from "url";
289
- import fs from "fs";
290
- var CONFIG_FILES = [
291
- "boltdocs.config.js",
292
- "boltdocs.config.mjs",
293
- "boltdocs.config.ts"
294
- ];
295
- async function resolveConfig(docsDir, root = process.cwd()) {
296
- const projectRoot = root;
297
- const defaults = {
298
- docsDir: path2.resolve(docsDir),
299
- themeConfig: {
300
- title: "Boltdocs",
301
- description: "A Vite documentation framework",
302
- navbar: [
303
- { text: "Home", link: "/" },
304
- { text: "Documentation", link: "/docs" }
305
- ]
306
- }
307
- };
308
- for (const filename of CONFIG_FILES) {
309
- const configPath = path2.resolve(projectRoot, filename);
310
- if (fs.existsSync(configPath)) {
311
- try {
312
- const isTest = process.env.NODE_ENV === "test" || global.__vitest_worker__;
313
- const fileUrl = pathToFileURL(configPath).href + (isTest ? "" : "?t=" + Date.now());
314
- const mod = await import(fileUrl);
315
- const userConfig = mod.default || mod;
316
- const userThemeConfig = userConfig.themeConfig || userConfig;
317
- return {
318
- docsDir: path2.resolve(docsDir),
319
- themeConfig: {
320
- ...defaults.themeConfig,
321
- ...userThemeConfig
322
- },
323
- i18n: userConfig.i18n,
324
- versions: userConfig.versions,
325
- siteUrl: userConfig.siteUrl,
326
- plugins: userConfig.plugins || []
327
- };
328
- } catch (e) {
329
- console.warn(`[boltdocs] Failed to load config from ${filename}:`, e);
330
- }
331
- }
332
- }
333
- return defaults;
334
- }
335
-
336
- // src/node/ssg/index.ts
337
- import fs2 from "fs";
338
- import path3 from "path";
339
- import { fileURLToPath } from "url";
340
- import { createRequire } from "module";
341
-
342
- // src/node/ssg/meta.ts
343
- function replaceMetaTags(html, meta) {
344
- const title = escapeHtml(meta.title);
345
- const description = escapeHtml(meta.description);
346
- return html.replace(/<title>.*?<\/title>/, `<title>${title}</title>`).replace(
347
- /(<meta name="description" content=")[^"]*(")/,
348
- `$1${description}$2`
349
- ).replace(/(<meta property="og:title" content=")[^"]*(")/, `$1${title}$2`).replace(
350
- /(<meta property="og:description" content=")[^"]*(")/,
351
- `$1${description}$2`
352
- ).replace(/(<meta name="twitter:title" content=")[^"]*(")/, `$1${title}$2`).replace(
353
- /(<meta name="twitter:description" content=")[^"]*(")/,
354
- `$1${description}$2`
355
- );
356
- }
357
-
358
- // src/node/ssg/sitemap.ts
359
- function generateSitemap(routePaths, config) {
360
- const baseUrl = config?.siteUrl?.replace(/\/$/, "") || "https://example.com";
361
- const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
362
- const rootEntries = [{ url: "/", priority: "1.0", changefreq: "daily" }];
363
- if (config?.i18n) {
364
- const defaultLocale = config.i18n.defaultLocale;
365
- for (const locale of Object.keys(config.i18n.locales)) {
366
- if (locale !== defaultLocale) {
367
- rootEntries.push({
368
- url: `/${locale}/`,
369
- priority: "1.0",
370
- changefreq: "daily"
371
- });
372
- }
373
- }
374
- }
375
- const entries = [
376
- ...rootEntries,
377
- ...routePaths.map((p) => ({
378
- url: p,
379
- priority: "0.8",
380
- changefreq: "weekly"
381
- }))
382
- ];
383
- return `<?xml version="1.0" encoding="UTF-8"?>
1
+ import{a as $,b as G,c as H,d as it,e as nt,f as D,g as J,h as rt,i as _,j as X,k as j,l as st,m as at}from"../chunk-MFU7Q6WF.mjs";import"../chunk-JZXLCA2E.mjs";import{loadEnv as zt}from"vite";import jt from"fast-glob";var R=new st({name:"routes"});function K(){R.invalidateAll()}function Z(o){R.invalidate(o)}import F from"path";import Dt from"github-slugger";function lt(o,r,i,p){let e=decodeURIComponent(o),c=F.resolve(e),l=F.resolve(r),u=$(F.relative(l,c));if(u.startsWith("../")||u===".."||c.includes("\0"))throw new Error(`Security breach: File is outside of docs directory or contains null bytes: ${o}`);let{data:t,content:n}=nt(o),s=u.split("/"),a,f;if(p?.versions&&s.length>0){let C=s[0];p.versions.versions[C]&&(f=C,s=s.slice(1))}if(p?.i18n&&s.length>0){let C=s[0];p.i18n.locales[C]&&(a=C,s=s.slice(1))}let v;if(s.length>0){let C=s[0].match(/^\((.+)\)$/);C&&(v=C[1].toLowerCase(),s=s.slice(1))}let d=s.join("/"),m;t.permalink?m=t.permalink.startsWith("/")?t.permalink:`/${t.permalink}`:m=rt(d||"index.md");let g=i;f&&(g+="/"+f),a&&(g+="/"+a),g+=m==="/"?"":m,(!g||g==="")&&(g="/");let y=s[s.length-1],k=G(y),x=G(F.basename(o,F.extname(o))),h=t.sidebarPosition??H(y),w=s.length>=2?s[0]:void 0,S=w?G(w):void 0,L=s.length>=2&&/^index\.mdx?$/.test(k),$t=new Dt,tt=[],wt=/^(#{2,4})\s+(.+)$/gm,V;for(;(V=wt.exec(n))!==null;){let C=V[1].length,St=V[2].replace(/\[([^\]]+)\]\([^\)]+\)/g,"$1").replace(/[_*`]/g,"").trim(),ot=_(St).trim(),Mt=$t.slug(ot);tt.push({level:C,text:ot,id:Mt})}let kt=t.title?_(String(t.title)):x,W=t.description?_(String(t.description)):"";!W&&n&&(W=X(n.replace(/^#+.*$/gm,"").replace(/\[([^\]]+)\]\([^\)]+\)/g,"$1").replace(/[_*`]/g,"").replace(/\s+/g," ")).trim().slice(0,160));let Rt=t.badge?_(String(t.badge)):void 0,et=t.icon?String(t.icon):void 0,Bt=Tt(n);return{route:{path:g,componentPath:o,filePath:u,title:kt,description:W,sidebarPosition:h,headings:tt,locale:a,version:f,badge:Rt,icon:et,tab:v,_content:Bt,_rawContent:n},relativeDir:S,isGroupIndex:L,inferredTab:v,groupMeta:L?{title:t.groupTitle||t.title||(S?j(S):""),position:t.groupPosition??t.sidebarPosition??(w?H(w):void 0),icon:et}:void 0,inferredGroupPosition:w?H(w):void 0}}function Tt(o){let r=o.replace(/^#+.*$/gm,"").replace(/\[([^\]]+)\]\([^\)]+\)/g,"$1").replace(/\{[^\}]+\}/g,"").replace(/[_*`]/g,"").replace(/\s+/g," ");return X(r).trim()}function dt(o){return o.sort((r,i)=>!r.group&&!i.group?ct(r,i):r.group?i.group?r.group!==i.group?_t(r,i):ct(r,i):1:-1)}function ct(o,r){return o.sidebarPosition!==void 0&&r.sidebarPosition!==void 0?o.sidebarPosition-r.sidebarPosition:o.sidebarPosition!==void 0?-1:r.sidebarPosition!==void 0?1:o.title.localeCompare(r.title)}function _t(o,r){return o.groupPosition!==void 0&&r.groupPosition!==void 0?o.groupPosition-r.groupPosition:o.groupPosition!==void 0?-1:r.groupPosition!==void 0?1:(o.groupTitle||o.group).localeCompare(r.groupTitle||r.group)}var E=new Map;async function I(o,r,i="/docs"){let p=performance.now();R.load(),E.clear(),(process.env.BOLTDOCS_FORCE_REPARSE==="true"||r?.i18n)&&R.invalidateAll();let e=await jt(["**/*.md","**/*.mdx"],{cwd:o,absolute:!0,suppressErrors:!0,followSymbolicLinks:!1});R.pruneStale(new Set(e));let c=50,l=[],u=0;for(let d=0;d<e.length;d+=c){let m=e.slice(d,d+c),g=await Promise.all(m.map(async y=>{let k=R.get(y);if(k)return u++,k;let x=lt(y,o,i,r);return R.set(y,x),x}));l.push(...g),d+c<e.length&&await new Promise(y=>setImmediate(y))}R.save();let t=new Map,n=[];for(let d of l)if(d.isGroupIndex&&d.relativeDir&&n.push(d),d.relativeDir){let m=t.get(d.relativeDir);m?(m.position===void 0&&d.inferredGroupPosition!==void 0&&(m.position=d.inferredGroupPosition),!m.icon&&d.route.icon&&(m.icon=d.route.icon)):(m={title:j(d.relativeDir),position:d.inferredGroupPosition,icon:d.route.icon},t.set(d.relativeDir,m))}for(let d of n){let m=t.get(d.relativeDir);d.groupMeta&&(m.title=d.groupMeta.title,d.groupMeta.position!==void 0&&(m.position=d.groupMeta.position),d.groupMeta.icon&&(m.icon=d.groupMeta.icon))}let s=new Array(l.length);for(let d=0;d<l.length;d++){let m=l[d],g=m.relativeDir,y=g?t.get(g):void 0;s[d]={...m.route,group:g,groupTitle:y?.title||(g?j(g):void 0),groupPosition:y?.position,groupIcon:y?.icon}}let a=s;if(r?.i18n){let d=Ft(s,r,i);a=[...s,...d]}let f=dt(a),v=performance.now()-p;return console.log(`[boltdocs] Route generation: ${v.toFixed(2)}ms (${e.length} files, ${u} cache hits)`),f}function Ft(o,r,i){let p=r.i18n.defaultLocale,e=Object.keys(r.i18n.locales),c=[],l=new Map,u=[];for(let t of o){let n=t.locale||p;l.has(n)||l.set(n,new Set),l.get(n).add(t.path),n===p&&u.push(t)}for(let t of e){if(t===p)continue;let n=l.get(t)||new Set;for(let s of u){let a=Et(s.path,p,t,i);n.has(a)||c.push({...s,path:a,locale:t})}}return c}function Et(o,r,i,p){let e=`${o}:${i}`,c=E.get(e);if(c)return c;let l=p,u=o.match(new RegExp(`^${p}/(v[0-9]+)`));u&&(l+="/"+u[1]);let t=o.substring(l.length),n=`/${r}`;if(t.startsWith(n+"/"))t="/"+i+"/"+t.substring(n.length+1);else if(t===n)t="/"+i;else if(t==="/"||t==="")t="/"+i;else{let a=t.startsWith("/")?"":"/";t="/"+i+a+t}let s=l+t;return E.size>2e3&&E.clear(),E.set(e,s),s}import{ViteImageOptimizer as Ut}from"vite-plugin-image-optimizer";import Q from"path";import It from"fs";import{loadConfigFromFile as Ot}from"vite";var N=["boltdocs.config.js","boltdocs.config.mjs","boltdocs.config.ts"];async function z(o,r=process.cwd()){let i=r,p={docsDir:Q.resolve(o),themeConfig:{title:"Boltdocs",description:"A Vite documentation framework",navbar:[{label:"Home",href:"/"},{label:"Documentation",href:"/docs"}],codeTheme:{light:"github-light",dark:"github-dark"},poweredBy:!0,breadcrumbs:!0}},e={};for(let t of N){let n=Q.resolve(i,t);if(It.existsSync(n))try{let s=await Ot({command:"serve",mode:"development"},n,i);if(s){e=s.config;break}}catch(s){console.warn(`[boltdocs] Failed to load config from ${t}:`,s)}}let l={...{title:e.title,description:e.description,logo:e.logo,navbar:e.navbar,sidebar:e.sidebar,socialLinks:e.socialLinks,footer:e.footer,githubRepo:e.githubRepo,tabs:e.tabs},...e.themeConfig||{}},u=Object.fromEntries(Object.entries(l).filter(([t,n])=>n!==void 0));return u.navbar&&(u.navbar=u.navbar.map(t=>({label:t.label||t.text||"",href:t.href||t.link||t.to||"",items:t.items?.map(n=>({label:n.label||n.text||"",href:n.href||n.link||n.to||""}))}))),{docsDir:Q.resolve(o),themeConfig:{...p.themeConfig,...u,codeTheme:u.codeTheme||(e.themeConfig||e).codeTheme||p.themeConfig?.codeTheme},i18n:e.i18n,versions:e.versions,siteUrl:e.siteUrl,plugins:e.plugins||[],external:e.external,integrations:e.integrations}}import T from"fs";import M from"path";import{fileURLToPath as Lt}from"url";import{createRequire as Gt}from"module";function pt(o,r){let i=D(r.title),p=D(r.description);return o.replace(/<title>.*?<\/title>/,`<title>${i}</title>`).replace(/(<meta name="description" content=")[^"]*(")/,`$1${p}$2`).replace(/(<meta property="og:title" content=")[^"]*(")/,`$1${i}$2`).replace(/(<meta property="og:description" content=")[^"]*(")/,`$1${p}$2`).replace(/(<meta name="twitter:title" content=")[^"]*(")/,`$1${i}$2`).replace(/(<meta name="twitter:description" content=")[^"]*(")/,`$1${p}$2`)}function mt(o,r){let i=r?.siteUrl?.replace(/\/$/,"")||"https://example.com",p=new Date().toISOString().split("T")[0],e=[{url:"/",priority:"1.0",changefreq:"daily"}];if(r?.i18n){let l=r.i18n.defaultLocale;for(let u of Object.keys(r.i18n.locales))u!==l&&e.push({url:`/${u}/`,priority:"1.0",changefreq:"daily"})}return`<?xml version="1.0" encoding="UTF-8"?>
384
2
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
385
- ${entries.map(
386
- (e) => ` <url>
387
- <loc>${escapeXml(baseUrl)}${escapeXml(e.url)}</loc>
388
- <lastmod>${today}</lastmod>
389
- <changefreq>${e.changefreq}</changefreq>
390
- <priority>${e.priority}</priority>
391
- </url>`
392
- ).join("\n")}
393
- </urlset>`;
394
- }
395
-
396
- // src/node/ssg/index.ts
397
- var _filename = fileURLToPath(import.meta.url);
398
- var _dirname = path3.dirname(_filename);
399
- var _require = createRequire(import.meta.url);
400
- async function generateStaticPages(options) {
401
- const { docsDir, docsDirName, outDir, config } = options;
402
- const routes = await generateRoutes(docsDir, config);
403
- const siteTitle = config?.themeConfig?.title || "Boltdocs";
404
- const siteDescription = config?.themeConfig?.description || "";
405
- const ssrModulePath = path3.resolve(_dirname, "../client/ssr.js");
406
- if (!fs2.existsSync(ssrModulePath)) {
407
- console.error(
408
- "[boltdocs] SSR module not found at",
409
- ssrModulePath,
410
- "- Did you build the core package?"
411
- );
412
- return;
413
- }
414
- const { render } = _require(ssrModulePath);
415
- const templatePath = path3.join(outDir, "index.html");
416
- if (!fs2.existsSync(templatePath)) {
417
- console.warn("[boltdocs] No index.html found in outDir, skipping SSG.");
418
- return;
419
- }
420
- const template = fs2.readFileSync(templatePath, "utf-8");
421
- await Promise.all(
422
- routes.map(async (route) => {
423
- const pageTitle = `${route.title} | ${siteTitle}`;
424
- const pageDescription = route.description || siteDescription;
425
- const fakeModules = {};
426
- fakeModules[route.componentPath] = { default: () => {
427
- } };
428
- try {
429
- const appHtml = await render({
430
- path: route.path,
431
- routes,
432
- config: config || {},
433
- docsDirName,
434
- modules: fakeModules,
435
- homePage: void 0
436
- // No custom home page for now
437
- });
438
- const html = replaceMetaTags(template, {
439
- title: escapeHtml(pageTitle),
440
- description: escapeHtml(pageDescription)
441
- }).replace("<!--app-html-->", appHtml).replace(`<div id="root"></div>`, `<div id="root">${appHtml}</div>`);
442
- const routeDir = path3.join(outDir, route.path);
443
- await fs2.promises.mkdir(routeDir, { recursive: true });
444
- await fs2.promises.writeFile(
445
- path3.join(routeDir, "index.html"),
446
- html,
447
- "utf-8"
448
- );
449
- } catch (e) {
450
- console.error(`[boltdocs] Error SSR rendering route ${route.path}:`, e);
451
- }
452
- })
453
- );
454
- const sitemap = generateSitemap(
455
- routes.map((r) => r.path),
456
- config
457
- );
458
- fs2.writeFileSync(path3.join(outDir, "sitemap.xml"), sitemap, "utf-8");
459
- console.log(
460
- `[boltdocs] Generated ${routes.length} static pages + sitemap.xml`
461
- );
462
- const { flushCache } = await import("../cache-KNL5B4EE.mjs");
463
- await flushCache();
464
- }
465
-
466
- // src/node/plugin/index.ts
467
- import path5 from "path";
468
-
469
- // src/node/plugin/entry.ts
470
- import path4 from "path";
471
- function generateEntryCode(options, config) {
472
- const homeImport = options.homePage ? `import HomePage from '${normalizePath(options.homePage)}';` : "";
473
- const homeOption = options.homePage ? "homePage: HomePage," : "";
474
- const customCssImport = options.customCss ? `import '${normalizePath(options.customCss)}';` : "";
475
- const pluginComponents = config?.plugins?.flatMap((p) => Object.entries(p.components || {})) || [];
476
- const componentImports = pluginComponents.map(
477
- ([
478
- name,
479
- path6
480
- ]) => `import * as _comp_${name} from '${normalizePath(path6)}';
481
- const ${name} = _comp_${name}.default || _comp_${name}['${name}'] || _comp_${name};`
482
- ).join("\n");
483
- const componentMap = pluginComponents.map(([name]) => name).join(", ");
484
- const docsDirName = path4.basename(options.docsDir || "docs");
485
- return `
3
+ ${[...e,...o.map(l=>({url:l,priority:"0.8",changefreq:"weekly"}))].map(l=>` <url>
4
+ <loc>${J(i)}${J(l.url)}</loc>
5
+ <lastmod>${p}</lastmod>
6
+ <changefreq>${l.changefreq}</changefreq>
7
+ <priority>${l.priority}</priority>
8
+ </url>`).join(`
9
+ `)}
10
+ </urlset>`}var Ht=Lt(import.meta.url),ut=M.dirname(Ht),gt=Gt(import.meta.url);async function Y(o){let{docsDir:r,docsDirName:i,outDir:p,config:e}=o,c=await I(r,e),l=e?.themeConfig?.title||"Boltdocs",u=e?.themeConfig?.description||"",t=M.resolve(ut,"../client/ssr.js");if(!T.existsSync(t)){console.error("[boltdocs] SSR module not found at",t,"- Did you build the core package?");return}let n=gt("module"),s=n.prototype.require;n.prototype.require=function(g,...y){return g==="virtual:boltdocs-layout"?{__esModule:!0,default:function(x){try{let w=s.apply(this,[M.resolve(ut,"../client/index.js")]).DefaultLayout||(({children:L})=>L);return s.apply(this,["react"]).createElement(w,x)}catch{return x.children}}}:s.apply(this,[g,...y])};let{render:a}=gt(t);n.prototype.require=s;let f=M.join(p,"index.html");if(!T.existsSync(f)){console.warn("[boltdocs] No index.html found in outDir, skipping SSG.");return}let v=T.readFileSync(f,"utf-8");await Promise.all(c.map(async g=>{let y=`${g.title} | ${l}`,k=g.description||u,x={};x[`/${i}/${g.filePath}`]={default:()=>null};try{let h=await a({path:g.path,routes:c,config:e||{},docsDirName:i,modules:x,homePage:void 0}),w=pt(v,{title:D(y),description:D(k)}).replace("<!--app-html-->",h).replace('<div id="root"></div>',`<div id="root">${h}</div>`),S=M.join(p,g.path);await T.promises.mkdir(S,{recursive:!0}),await T.promises.writeFile(M.join(S,"index.html"),w,"utf-8")}catch(h){console.error(`[boltdocs] Error SSR rendering route ${g.path}:`,h&&(h.stack||h))}}));let d=mt(c.map(g=>g.path),e);T.writeFileSync(M.join(p,"sitemap.xml"),d,"utf-8"),console.log(`[boltdocs] Generated ${c.length} static pages + sitemap.xml`);let{flushCache:m}=await import("../cache-7G6D532T.mjs");await m()}import B from"path";import Nt from"path";function ft(o,r){let i=o.homePage?`import HomePage from '${$(o.homePage)}';`:"",p=o.homePage?"homePage: HomePage,":"",e=r?.plugins?.flatMap(a=>Object.entries(a.components||{}))||[],c=e.map(([a,f])=>`import * as _comp_${a} from '${$(f)}';
11
+ const ${a} = _comp_${a}.default || _comp_${a}['${a}'] || _comp_${a};`).join(`
12
+ `),l=e.map(([a])=>a).join(", "),u=Nt.basename(o.docsDir||"docs"),t=Object.entries(r?.external||{}),n=t.map(([a,f],v)=>`import _ext_${v} from '${$(f)}';`).join(`
13
+ `),s=t.length>0?`externalPages: { ${t.map(([a],f)=>`"${a}": _ext_${f}`).join(", ")} },`:"";return`
486
14
  import { createBoltdocsApp as _createApp } from 'boltdocs/client';
487
- import 'boltdocs/style.css';
488
- ${customCssImport}
489
15
  import _routes from 'virtual:boltdocs-routes';
490
16
  import _config from 'virtual:boltdocs-config';
491
- ${homeImport}
492
- ${componentImports}
17
+ import _user_mdx_components from 'virtual:boltdocs-mdx-components';
18
+ ${i}
19
+ ${c}
20
+ ${n}
493
21
 
494
22
  _createApp({
495
23
  target: '#root',
496
24
  routes: _routes,
497
- docsDirName: '${docsDirName}',
25
+ docsDirName: '${u}',
498
26
  config: _config,
499
- modules: import.meta.glob('/${docsDirName}/**/*.{md,mdx}'),
27
+ modules: import.meta.glob('/${u}/**/*.{md,mdx}'),
500
28
  hot: import.meta.hot,
501
- ${homeOption}
502
- components: { ${componentMap} },
29
+ ${p}
30
+ ${s}
31
+ components: { ${l}${l?", ":""} ...(_user_mdx_components || {}) },
503
32
  });
504
- `;
505
- }
506
-
507
- // src/node/plugin/html.ts
508
- function injectHtmlMeta(html, config) {
509
- const title = config.themeConfig?.title || "Boltdocs";
510
- const description = config.themeConfig?.description || "";
511
- const seoTags = [
512
- `<meta name="description" content="${description}">`,
513
- `<meta property="og:title" content="${title}">`,
514
- `<meta property="og:description" content="${description}">`,
515
- `<meta property="og:type" content="website">`,
516
- `<meta name="twitter:card" content="summary">`,
517
- `<meta name="twitter:title" content="${title}">`,
518
- `<meta name="twitter:description" content="${description}">`,
519
- `<meta name="generator" content="Boltdocs">`
520
- ].join("\n ");
521
- const themeScript = `
33
+ `}function ht(o,r){let i=r.themeConfig?.title||"Boltdocs",p=r.themeConfig?.description||"",e=[`<meta name="description" content="${p}">`,`<meta property="og:title" content="${i}">`,`<meta property="og:description" content="${p}">`,'<meta property="og:type" content="website">','<meta name="twitter:card" content="summary">',`<meta name="twitter:title" content="${i}">`,`<meta name="twitter:description" content="${p}">`,'<meta name="generator" content="Boltdocs">'].join(`
34
+ `),c=`
522
35
  <script>
523
36
  (function() {
524
37
  try {
@@ -534,229 +47,11 @@ function injectHtmlMeta(html, config) {
534
47
  } catch (e) {}
535
48
  })();
536
49
  </script>
537
- `;
538
- html = html.replace(/<title>.*?<\/title>/, `<title>${title}</title>`);
539
- html = html.replace("</head>", ` ${seoTags}
540
- ${themeScript} </head>`);
541
- if (!html.includes("src/main")) {
542
- html = html.replace(
543
- "</body>",
544
- ' <script type="module">import "virtual:boltdocs-entry";</script>\n </body>'
545
- );
546
- }
547
- return html;
548
- }
549
-
550
- // src/node/plugin/index.ts
551
- function boltdocsPlugin(options = {}, passedConfig) {
552
- const docsDir = path5.resolve(process.cwd(), options.docsDir || "docs");
553
- const normalizedDocsDir = normalizePath(docsDir);
554
- let config = passedConfig;
555
- let viteConfig;
556
- let isBuild = false;
557
- const extraVitePlugins = config?.plugins?.flatMap((p) => p.vitePlugins || []) || [];
558
- return [
559
- {
560
- name: "vite-plugin-boltdocs",
561
- enforce: "pre",
562
- async config(userConfig, env) {
563
- isBuild = env.command === "build";
564
- const envDir = userConfig.envDir || process.cwd();
565
- const envs = loadEnv(env.mode, envDir, "");
566
- Object.assign(process.env, envs);
567
- if (!config) {
568
- config = await resolveConfig(docsDir);
569
- }
570
- if (!options.customCss && config.themeConfig?.customCss) {
571
- options.customCss = config.themeConfig.customCss;
572
- }
573
- return {
574
- optimizeDeps: { include: ["react", "react-dom"] }
575
- };
576
- },
577
- configResolved(resolved) {
578
- viteConfig = resolved;
579
- },
580
- configureServer(server) {
581
- const configPaths = CONFIG_FILES.map(
582
- (c) => path5.resolve(process.cwd(), c)
583
- );
584
- server.watcher.add(configPaths);
585
- const handleFileEvent = async (file, type) => {
586
- const normalized = normalizePath(file);
587
- if (CONFIG_FILES.some((c) => normalized.endsWith(c))) {
588
- server.restart();
589
- return;
590
- }
591
- if (!normalized.startsWith(normalizedDocsDir) || !isDocFile(normalized))
592
- return;
593
- if (type === "add" || type === "unlink") {
594
- invalidateRouteCache();
595
- } else {
596
- invalidateFile(file);
597
- }
598
- const newRoutes = await generateRoutes(docsDir, config);
599
- const routesMod = server.moduleGraph.getModuleById(
600
- "\0virtual:boltdocs-routes"
601
- );
602
- if (routesMod) server.moduleGraph.invalidateModule(routesMod);
603
- server.ws.send({
604
- type: "custom",
605
- event: "boltdocs:routes-update",
606
- data: newRoutes
607
- });
608
- };
609
- server.watcher.on("add", (f) => handleFileEvent(f, "add"));
610
- server.watcher.on("unlink", (f) => handleFileEvent(f, "unlink"));
611
- server.watcher.on("change", (f) => handleFileEvent(f, "change"));
612
- },
613
- resolveId(id) {
614
- if (id === "virtual:boltdocs-routes" || id === "virtual:boltdocs-config" || id === "virtual:boltdocs-entry") {
615
- return "\0" + id;
616
- }
617
- },
618
- async load(id) {
619
- if (id === "\0virtual:boltdocs-routes") {
620
- const routes = await generateRoutes(docsDir, config);
621
- return `export default ${JSON.stringify(routes, null, 2)};`;
622
- }
623
- if (id === "\0virtual:boltdocs-config") {
624
- const clientConfig = {
625
- themeConfig: config?.themeConfig,
626
- i18n: config?.i18n,
627
- versions: config?.versions,
628
- siteUrl: config?.siteUrl
629
- };
630
- return `export default ${JSON.stringify(clientConfig, null, 2)};`;
631
- }
632
- if (id === "\0virtual:boltdocs-entry") {
633
- const code = generateEntryCode(options, config);
634
- return code;
635
- }
636
- },
637
- transformIndexHtml: {
638
- order: "pre",
639
- handler(html) {
640
- return injectHtmlMeta(html, config);
641
- }
642
- },
643
- async closeBundle() {
644
- if (!isBuild) return;
645
- const outDir = viteConfig?.build?.outDir ? path5.resolve(viteConfig.root, viteConfig.build.outDir) : path5.resolve(process.cwd(), "dist");
646
- const docsDirName = path5.basename(docsDir || "docs");
647
- await generateStaticPages({ docsDir, docsDirName, outDir, config });
648
- const { flushCache } = await import("../cache-KNL5B4EE.mjs");
649
- await flushCache();
650
- }
651
- },
652
- ViteImageOptimizer({
653
- includePublic: true,
654
- png: { quality: 80 },
655
- jpeg: { quality: 80 },
656
- jpg: { quality: 80 },
657
- webp: { quality: 80 },
658
- avif: { quality: 80 },
659
- svg: {
660
- multipass: true,
661
- plugins: [
662
- {
663
- name: "preset-default",
664
- params: { overrides: { removeViewBox: false } }
665
- }
666
- ]
667
- }
668
- }),
669
- ...extraVitePlugins.filter((p) => !!p)
670
- ];
671
- }
672
-
673
- // src/node/mdx.ts
674
- import mdxPlugin from "@mdx-js/rollup";
675
- import remarkGfm from "remark-gfm";
676
- import remarkFrontmatter from "remark-frontmatter";
677
- import rehypeSlug from "rehype-slug";
678
- import rehypePrettyCode from "rehype-pretty-code";
679
- import crypto from "crypto";
680
- var mdxCache = new TransformCache("mdx");
681
- var mdxCacheLoaded = false;
682
- function boltdocsMdxPlugin(config, compiler = mdxPlugin) {
683
- const extraRemarkPlugins = config?.plugins?.flatMap((p) => p.remarkPlugins || []) || [];
684
- const extraRehypePlugins = config?.plugins?.flatMap((p) => p.rehypePlugins || []) || [];
685
- const baseMdxPlugin = compiler({
686
- remarkPlugins: [remarkGfm, remarkFrontmatter, ...extraRemarkPlugins],
687
- rehypePlugins: [
688
- rehypeSlug,
689
- ...extraRehypePlugins,
690
- [
691
- rehypePrettyCode,
692
- {
693
- theme: config?.themeConfig?.codeTheme || "one-dark-pro",
694
- keepBackground: false
695
- }
696
- ]
697
- ],
698
- jsxRuntime: "automatic",
699
- providerImportSource: "@mdx-js/react"
700
- });
701
- if (baseMdxPlugin.isMock) {
702
- console.log("MDX PLUGIN IS MOCKED");
703
- }
704
- return {
705
- ...baseMdxPlugin,
706
- name: "vite-plugin-boltdocs-mdx",
707
- async buildStart() {
708
- hits = 0;
709
- total = 0;
710
- if (!mdxCacheLoaded) {
711
- mdxCache.load();
712
- mdxCacheLoaded = true;
713
- }
714
- if (baseMdxPlugin.buildStart) {
715
- await baseMdxPlugin.buildStart.call(this);
716
- }
717
- },
718
- async transform(code, id, options) {
719
- if (!id.endsWith(".md") && !id.endsWith(".mdx")) {
720
- return baseMdxPlugin.transform?.call(this, code, id, options);
721
- }
722
- total++;
723
- const contentHash = crypto.createHash("md5").update(code).digest("hex");
724
- const cacheKey = `${id}:${contentHash}`;
725
- const cached = mdxCache.get(cacheKey);
726
- if (cached) {
727
- hits++;
728
- return { code: cached, map: null };
729
- }
730
- const result = await baseMdxPlugin.transform.call(
731
- this,
732
- code,
733
- id,
734
- options
735
- );
736
- if (result && typeof result === "object" && result.code) {
737
- mdxCache.set(cacheKey, result.code);
738
- }
739
- return result;
740
- },
741
- async buildEnd() {
742
- mdxCache.save();
743
- await mdxCache.flush();
744
- if (baseMdxPlugin.buildEnd) {
745
- await baseMdxPlugin.buildEnd.call(this);
746
- }
747
- }
748
- };
749
- }
750
- var hits = 0;
751
- var total = 0;
752
-
753
- // src/node/index.ts
754
- async function boltdocs(options) {
755
- const docsDir = options?.docsDir || "docs";
756
- const config = await resolveConfig(docsDir);
757
- return [...boltdocsPlugin(options, config), boltdocsMdxPlugin(config)];
758
- }
759
- export {
760
- boltdocs as default,
761
- generateStaticPages
762
- };
50
+ `;return o=o.replace(/<title>.*?<\/title>/,`<title>${i}</title>`),o=o.replace("</head>",` ${e}
51
+ ${c} </head>`),o.includes("src/main")||(o=o.replace("</body>",` <script type="module">import "virtual:boltdocs-entry";</script>
52
+ </body>`)),o}import yt from"fs";function xt(o={},r){let i=B.resolve(process.cwd(),o.docsDir||"docs"),p=$(i),e=r,c,l=!1,u=e?.plugins?.flatMap(t=>t.vitePlugins||[])||[];return[{name:"vite-plugin-boltdocs",enforce:"pre",async config(t,n){l=n.command==="build";let s=t.envDir||process.cwd(),a=zt(n.mode,s,"");return Object.assign(process.env,a),e||(e=await z(i)),{optimizeDeps:{include:["react","react-dom"]}}},configResolved(t){c=t},configureServer(t){let n=N.map(m=>B.resolve(process.cwd(),m)),s=["tsx","jsx"],a=s.map(m=>B.resolve(i,`layout.${m}`)),f=["tsx","ts","jsx","js"],v=f.map(m=>B.resolve(i,`mdx-components.${m}`));t.watcher.add([...n,...v,...a]);let d=async(m,g)=>{let y=$(m);if(N.some(h=>y.endsWith(h))){t.restart();return}if(f.some(h=>y.endsWith(`mdx-components.${h}`))){let h=t.moduleGraph.getModuleById("\0virtual:boltdocs-mdx-components");h&&t.moduleGraph.invalidateModule(h),t.ws.send({type:"full-reload"});return}if(s.some(h=>y.endsWith(`layout.${h}`))){let h=t.moduleGraph.getModuleById("\0virtual:boltdocs-layout");h&&t.moduleGraph.invalidateModule(h),t.ws.send({type:"full-reload"});return}if(!y.startsWith(p)||!it(y))return;g==="add"||g==="unlink"?K():Z(m);let k=await I(i,e),x=t.moduleGraph.getModuleById("\0virtual:boltdocs-routes");x&&t.moduleGraph.invalidateModule(x),t.ws.send({type:"custom",event:"boltdocs:routes-update",data:k})};t.watcher.on("add",m=>d(m,"add")),t.watcher.on("unlink",m=>d(m,"unlink")),t.watcher.on("change",m=>d(m,"change"))},resolveId(t){if(t==="virtual:boltdocs-routes"||t==="virtual:boltdocs-config"||t==="virtual:boltdocs-entry"||t==="virtual:boltdocs-mdx-components"||t==="virtual:boltdocs-layout")return"\0"+t},async load(t){if(t==="\0virtual:boltdocs-routes"){let n=await I(i,e);return`export default ${JSON.stringify(n,null,2)};`}if(t==="\0virtual:boltdocs-config"){let n={themeConfig:e?.themeConfig,integrations:e?.integrations,i18n:e?.i18n,versions:e?.versions,siteUrl:e?.siteUrl};return`export default ${JSON.stringify(n,null,2)};`}if(t==="\0virtual:boltdocs-entry")return ft(o,e);if(t==="\0virtual:boltdocs-mdx-components"){let n=["tsx","ts","jsx","js"],s=null;for(let a of n){let f=B.resolve(i,`mdx-components.${a}`);if(yt.existsSync(f)){s=f;break}}if(s){let a=$(s);return`import * as components from '${a}';
53
+ const mdxComponents = components.default || components;
54
+ export default mdxComponents;
55
+ export * from '${a}';`}return"export default {};"}if(t==="\0virtual:boltdocs-layout"){let n=["tsx","jsx"],s=null;for(let a of n){let f=B.resolve(i,`layout.${a}`);if(yt.existsSync(f)){s=f;break}}return s?`import UserLayout from '${$(s)}';
56
+ export default UserLayout;`:`import { DefaultLayout } from 'boltdocs/client';
57
+ export default DefaultLayout;`}},transformIndexHtml:{order:"pre",handler(t){return ht(t,e)}},async closeBundle(){if(!l)return;let t=c?.build?.outDir?B.resolve(c.root,c.build.outDir):B.resolve(process.cwd(),"dist"),n=B.basename(i||"docs");await Y({docsDir:i,docsDirName:n,outDir:t,config:e});let{flushCache:s}=await import("../cache-7G6D532T.mjs");await s()}},Ut({includePublic:!0,png:{quality:80},jpeg:{quality:80},jpg:{quality:80},webp:{quality:80},avif:{quality:80},svg:{multipass:!0,plugins:[{name:"preset-default"}]}}),...u.filter(t=>!!t)]}import qt from"@mdx-js/rollup";import At from"remark-gfm";import Vt from"remark-frontmatter";import Wt from"rehype-slug";import Jt from"crypto";import{visit as Pt}from"unist-util-visit";import{createHighlighter as Xt}from"shiki";var U=null;async function vt(o){if(U)return U;let r=typeof o=="object"?[o.light,o.dark]:[o??"github-dark"];return["github-light","github-dark"].forEach(i=>{r.includes(i)||r.push(i)}),U=await Xt({themes:r,langs:["tsx","jsx","ts","js","json","md","mdx","css","html","bash","sh","yaml","yml"]}),U}function Kt(o){return async r=>{let i=o?.themeConfig?.codeTheme??{light:"github-light",dark:"github-dark"},p=await vt(i);Pt(r,["mdxJsxFlowElement","mdxJsxTextElement"],e=>{if(e.name!=="ComponentPreview")return;let c=e.attributes?.find(n=>n.name==="code"),l="";if(c){if(typeof c.value=="string")l=c.value;else if(c.value?.type==="mdxJsxAttributeValueExpression"){let n=c.value.value??"";l=n.match(/^[`'"](.+)[`'"]$/)?.[1]??n}}if(!l)return;let u=typeof i=="object"?{themes:{light:i.light,dark:i.dark},lang:"tsx"}:{theme:i,lang:"tsx"},t=p.codeToHtml(l,u);e.attributes=(e.attributes??[]).filter(n=>n.name!=="highlightedHtml"),e.attributes.push({type:"mdxJsxAttribute",name:"highlightedHtml",value:t})})}}function Zt(o){return async r=>{let i=o?.themeConfig?.codeTheme||{light:"github-light",dark:"github-dark"},p=await vt(i);Pt(r,"element",e=>{if(e.tagName==="pre"&&e.children?.[0]?.tagName==="code"){let c=e.children[0],u=(c.properties?.className||[]).find(f=>f.startsWith("language-")),t=u?u.slice(9):"text",n=c.children[0]?.value||"",s={lang:t};typeof i=="object"?s.themes={light:i.light,dark:i.dark}:s.theme=i;let a=p.codeToHtml(n,s);e.properties.dataHighlighted="true",e.properties.highlightedHtml=a,e.children=[]}})}}var Qt="v3",O=new at("mdx"),bt=!1;function Ct(o,r=qt){let i=o?.plugins?.flatMap(c=>c.remarkPlugins||[])||[],p=o?.plugins?.flatMap(c=>c.rehypePlugins||[])||[],e=r({remarkPlugins:[At,Vt,[Kt,o],...i],rehypePlugins:[Wt,[Zt,o],...p],jsxRuntime:"automatic",providerImportSource:"@mdx-js/react"});return e.isMock&&console.log("MDX PLUGIN IS MOCKED"),{...e,name:"vite-plugin-boltdocs-mdx",async buildStart(){q=0,A=0,bt||(O.load(),bt=!0),e.buildStart&&await e.buildStart.call(this)},async transform(c,l,u){if(!l.endsWith(".md")&&!l.endsWith(".mdx"))return e.transform?.call(this,c,l,u);console.log(`[boltdocs] Transforming MDX: ${l}`),A++;let t=Jt.createHash("md5").update(c).digest("hex"),n=`${l}:${t}:${Qt}`,s=O.get(n);if(s)return q++,{code:s,map:null};let a=await e.transform.call(this,c,l,u);return a&&typeof a=="object"&&a.code&&O.set(n,a.code),a},async buildEnd(){console.log(`[boltdocs] MDX Cache Performance: ${q}/${A} hits (${Math.round(q/A*100)||0}%)`),O.save(),await O.flush(),e.buildEnd&&await e.buildEnd.call(this)}}}var q=0,A=0;async function Yt(o){let r=o?.docsDir||"docs",i=await z(r);return[...xt(o,i),Ct(i)]}export{Yt as default,Y as generateStaticPages};