boltdocs 1.10.2 → 1.11.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 (225) hide show
  1. package/package.json +29 -7
  2. package/src/client/app/config-context.tsx +18 -0
  3. package/src/client/app/docs-layout.tsx +14 -0
  4. package/src/client/app/index.tsx +132 -260
  5. package/src/client/app/mdx-component.tsx +52 -0
  6. package/src/client/app/mdx-components-context.tsx +23 -0
  7. package/src/client/app/mdx-page.tsx +20 -0
  8. package/src/client/app/preload.tsx +38 -30
  9. package/src/client/app/router.tsx +30 -0
  10. package/src/client/app/scroll-handler.tsx +40 -0
  11. package/src/client/app/theme-context.tsx +75 -0
  12. package/src/client/components/default-layout.tsx +80 -0
  13. package/src/client/components/docs-layout.tsx +105 -0
  14. package/src/client/components/icons-dev.tsx +74 -0
  15. package/src/client/components/mdx/admonition.tsx +107 -0
  16. package/src/client/components/mdx/badge.tsx +41 -0
  17. package/src/client/components/mdx/button.tsx +35 -0
  18. package/src/client/components/mdx/card.tsx +124 -0
  19. package/src/client/components/mdx/code-block.tsx +119 -0
  20. package/src/client/components/mdx/component-preview.tsx +47 -0
  21. package/src/client/components/mdx/component-props.tsx +83 -0
  22. package/src/client/components/mdx/field.tsx +66 -0
  23. package/src/client/components/mdx/file-tree.tsx +287 -0
  24. package/src/client/components/mdx/hooks/use-code-block.ts +56 -0
  25. package/src/client/components/mdx/hooks/use-component-preview.ts +16 -0
  26. package/src/client/components/mdx/hooks/useTable.ts +74 -0
  27. package/src/client/components/mdx/hooks/useTabs.ts +68 -0
  28. package/src/client/components/mdx/image.tsx +23 -0
  29. package/src/client/components/mdx/index.ts +53 -0
  30. package/src/client/components/mdx/link.tsx +38 -0
  31. package/src/client/components/mdx/list.tsx +192 -0
  32. package/src/client/components/mdx/table.tsx +156 -0
  33. package/src/client/components/mdx/tabs.tsx +135 -0
  34. package/src/client/components/mdx/video.tsx +68 -0
  35. package/src/client/components/primitives/breadcrumbs.tsx +79 -0
  36. package/src/client/components/primitives/button-group.tsx +54 -0
  37. package/src/client/components/primitives/button.tsx +145 -0
  38. package/src/client/components/primitives/helpers/observer.ts +120 -0
  39. package/src/client/components/primitives/index.ts +17 -0
  40. package/src/client/components/primitives/link.tsx +122 -0
  41. package/src/client/components/primitives/menu.tsx +159 -0
  42. package/src/client/components/primitives/navbar.tsx +359 -0
  43. package/src/client/components/primitives/navigation-menu.tsx +116 -0
  44. package/src/client/components/primitives/on-this-page.tsx +461 -0
  45. package/src/client/components/primitives/page-nav.tsx +87 -0
  46. package/src/client/components/primitives/popover.tsx +47 -0
  47. package/src/client/components/primitives/search-dialog.tsx +183 -0
  48. package/src/client/components/primitives/sidebar.tsx +154 -0
  49. package/src/client/components/primitives/tabs.tsx +90 -0
  50. package/src/client/components/primitives/tooltip.tsx +83 -0
  51. package/src/client/components/primitives/types.ts +11 -0
  52. package/src/client/components/ui-base/breadcrumbs.tsx +42 -0
  53. package/src/client/components/ui-base/copy-markdown.tsx +112 -0
  54. package/src/client/components/ui-base/error-boundary.tsx +52 -0
  55. package/src/client/components/ui-base/github-stars.tsx +27 -0
  56. package/src/client/components/ui-base/head.tsx +69 -0
  57. package/src/client/components/ui-base/loading.tsx +87 -0
  58. package/src/client/components/ui-base/navbar.tsx +138 -0
  59. package/src/client/components/ui-base/not-found.tsx +24 -0
  60. package/src/client/components/ui-base/on-this-page.tsx +152 -0
  61. package/src/client/components/ui-base/page-nav.tsx +39 -0
  62. package/src/client/components/ui-base/powered-by.tsx +19 -0
  63. package/src/client/components/ui-base/progress-bar.tsx +67 -0
  64. package/src/client/components/ui-base/search-dialog.tsx +82 -0
  65. package/src/client/components/ui-base/sidebar.tsx +104 -0
  66. package/src/client/components/ui-base/tabs.tsx +65 -0
  67. package/src/client/components/ui-base/theme-toggle.tsx +32 -0
  68. package/src/client/hooks/index.ts +12 -0
  69. package/src/client/hooks/use-breadcrumbs.ts +22 -0
  70. package/src/client/hooks/use-i18n.ts +84 -0
  71. package/src/client/hooks/use-localized-to.ts +95 -0
  72. package/src/client/hooks/use-location.ts +5 -0
  73. package/src/client/hooks/use-navbar.ts +60 -0
  74. package/src/client/hooks/use-onthispage.ts +23 -0
  75. package/src/client/hooks/use-page-nav.ts +22 -0
  76. package/src/client/hooks/use-routes.ts +72 -0
  77. package/src/client/hooks/use-search.ts +71 -0
  78. package/src/client/hooks/use-sidebar.ts +49 -0
  79. package/src/client/hooks/use-tabs.ts +43 -0
  80. package/src/client/hooks/use-version.ts +78 -0
  81. package/src/client/index.ts +55 -17
  82. package/src/client/integrations/codesandbox.ts +179 -0
  83. package/src/client/ssr.tsx +27 -16
  84. package/src/client/theme/neutral.css +360 -0
  85. package/src/client/types.ts +131 -27
  86. package/src/client/utils/cn.ts +6 -0
  87. package/src/client/utils/copy-clipboard.ts +22 -0
  88. package/src/client/utils/get-base-file-path.ts +21 -0
  89. package/src/client/utils/github.ts +121 -0
  90. package/src/client/utils/use-on-change.ts +15 -0
  91. package/src/client/virtual.d.ts +24 -0
  92. package/src/node/cache.ts +156 -156
  93. package/src/node/config.ts +159 -103
  94. package/src/node/index.ts +13 -13
  95. package/src/node/mdx.ts +213 -61
  96. package/src/node/plugin/entry.ts +29 -18
  97. package/src/node/plugin/html.ts +11 -11
  98. package/src/node/plugin/index.ts +161 -83
  99. package/src/node/plugin/types.ts +2 -4
  100. package/src/node/routes/cache.ts +6 -6
  101. package/src/node/routes/index.ts +206 -113
  102. package/src/node/routes/parser.ts +106 -81
  103. package/src/node/routes/sorter.ts +15 -15
  104. package/src/node/routes/types.ts +24 -24
  105. package/src/node/ssg/index.ts +46 -46
  106. package/src/node/ssg/meta.ts +4 -4
  107. package/src/node/ssg/options.ts +5 -5
  108. package/src/node/ssg/sitemap.ts +14 -14
  109. package/src/node/utils.ts +31 -31
  110. package/tsconfig.json +25 -20
  111. package/tsup.config.ts +23 -14
  112. package/dist/PackageManagerTabs-NVT7G625.mjs +0 -99
  113. package/dist/SearchDialog-AGVF6JBO.mjs +0 -194
  114. package/dist/SearchDialog-YPDOM7Q6.css +0 -2847
  115. package/dist/Video-KNTY5BNO.mjs +0 -6
  116. package/dist/cache-KNL5B4EE.mjs +0 -12
  117. package/dist/chunk-7SFUJWTB.mjs +0 -211
  118. package/dist/chunk-FFBNU6IJ.mjs +0 -386
  119. package/dist/chunk-FMTOYQLO.mjs +0 -37
  120. package/dist/chunk-TKLQWU7H.mjs +0 -1920
  121. package/dist/chunk-Z7JHYNAS.mjs +0 -57
  122. package/dist/client/index.css +0 -2847
  123. package/dist/client/index.d.mts +0 -372
  124. package/dist/client/index.d.ts +0 -372
  125. package/dist/client/index.js +0 -3630
  126. package/dist/client/index.mjs +0 -697
  127. package/dist/client/ssr.css +0 -2847
  128. package/dist/client/ssr.d.mts +0 -27
  129. package/dist/client/ssr.d.ts +0 -27
  130. package/dist/client/ssr.js +0 -2928
  131. package/dist/client/ssr.mjs +0 -33
  132. package/dist/config-BsFQ-ErD.d.mts +0 -159
  133. package/dist/config-BsFQ-ErD.d.ts +0 -159
  134. package/dist/node/index.d.mts +0 -91
  135. package/dist/node/index.d.ts +0 -91
  136. package/dist/node/index.js +0 -1187
  137. package/dist/node/index.mjs +0 -762
  138. package/dist/types-Dj-bfnC3.d.mts +0 -74
  139. package/dist/types-Dj-bfnC3.d.ts +0 -74
  140. package/src/client/theme/components/CodeBlock/CodeBlock.tsx +0 -61
  141. package/src/client/theme/components/CodeBlock/index.ts +0 -1
  142. package/src/client/theme/components/PackageManagerTabs/PackageManagerTabs.tsx +0 -131
  143. package/src/client/theme/components/PackageManagerTabs/index.ts +0 -1
  144. package/src/client/theme/components/PackageManagerTabs/pkg-tabs.css +0 -64
  145. package/src/client/theme/components/Playground/Playground.tsx +0 -180
  146. package/src/client/theme/components/Playground/index.ts +0 -1
  147. package/src/client/theme/components/Playground/playground.css +0 -238
  148. package/src/client/theme/components/Video/Video.tsx +0 -84
  149. package/src/client/theme/components/Video/index.ts +0 -1
  150. package/src/client/theme/components/Video/video.css +0 -41
  151. package/src/client/theme/components/mdx/Admonition.tsx +0 -80
  152. package/src/client/theme/components/mdx/Badge.tsx +0 -31
  153. package/src/client/theme/components/mdx/Button.tsx +0 -50
  154. package/src/client/theme/components/mdx/Card.tsx +0 -80
  155. package/src/client/theme/components/mdx/Field.tsx +0 -60
  156. package/src/client/theme/components/mdx/FileTree.tsx +0 -229
  157. package/src/client/theme/components/mdx/List.tsx +0 -57
  158. package/src/client/theme/components/mdx/Table.tsx +0 -151
  159. package/src/client/theme/components/mdx/Tabs.tsx +0 -123
  160. package/src/client/theme/components/mdx/index.ts +0 -27
  161. package/src/client/theme/components/mdx/mdx-components.css +0 -764
  162. package/src/client/theme/icons/bun.tsx +0 -62
  163. package/src/client/theme/icons/deno.tsx +0 -20
  164. package/src/client/theme/icons/discord.tsx +0 -12
  165. package/src/client/theme/icons/github.tsx +0 -15
  166. package/src/client/theme/icons/npm.tsx +0 -13
  167. package/src/client/theme/icons/pnpm.tsx +0 -72
  168. package/src/client/theme/icons/twitter.tsx +0 -12
  169. package/src/client/theme/styles/markdown.css +0 -394
  170. package/src/client/theme/styles/variables.css +0 -175
  171. package/src/client/theme/styles.css +0 -39
  172. package/src/client/theme/ui/Breadcrumbs/Breadcrumbs.tsx +0 -68
  173. package/src/client/theme/ui/Breadcrumbs/index.ts +0 -1
  174. package/src/client/theme/ui/CopyMarkdown/CopyMarkdown.tsx +0 -82
  175. package/src/client/theme/ui/CopyMarkdown/copy-markdown.css +0 -112
  176. package/src/client/theme/ui/CopyMarkdown/index.ts +0 -1
  177. package/src/client/theme/ui/ErrorBoundary/ErrorBoundary.tsx +0 -50
  178. package/src/client/theme/ui/ErrorBoundary/error-boundary.css +0 -55
  179. package/src/client/theme/ui/ErrorBoundary/index.ts +0 -1
  180. package/src/client/theme/ui/Footer/footer.css +0 -32
  181. package/src/client/theme/ui/Head/Head.tsx +0 -69
  182. package/src/client/theme/ui/Head/index.ts +0 -1
  183. package/src/client/theme/ui/LanguageSwitcher/LanguageSwitcher.tsx +0 -125
  184. package/src/client/theme/ui/LanguageSwitcher/index.ts +0 -1
  185. package/src/client/theme/ui/LanguageSwitcher/language-switcher.css +0 -98
  186. package/src/client/theme/ui/Layout/Layout.tsx +0 -203
  187. package/src/client/theme/ui/Layout/base.css +0 -106
  188. package/src/client/theme/ui/Layout/index.ts +0 -2
  189. package/src/client/theme/ui/Layout/pagination.css +0 -72
  190. package/src/client/theme/ui/Layout/responsive.css +0 -47
  191. package/src/client/theme/ui/Link/Link.tsx +0 -392
  192. package/src/client/theme/ui/Link/LinkPreview.tsx +0 -59
  193. package/src/client/theme/ui/Link/index.ts +0 -2
  194. package/src/client/theme/ui/Link/link-preview.css +0 -48
  195. package/src/client/theme/ui/Loading/Loading.tsx +0 -10
  196. package/src/client/theme/ui/Loading/index.ts +0 -1
  197. package/src/client/theme/ui/Loading/loading.css +0 -30
  198. package/src/client/theme/ui/Navbar/GithubStars.tsx +0 -27
  199. package/src/client/theme/ui/Navbar/Navbar.tsx +0 -193
  200. package/src/client/theme/ui/Navbar/Tabs.tsx +0 -99
  201. package/src/client/theme/ui/Navbar/index.ts +0 -2
  202. package/src/client/theme/ui/Navbar/navbar.css +0 -347
  203. package/src/client/theme/ui/NotFound/NotFound.tsx +0 -19
  204. package/src/client/theme/ui/NotFound/index.ts +0 -1
  205. package/src/client/theme/ui/NotFound/not-found.css +0 -64
  206. package/src/client/theme/ui/OnThisPage/OnThisPage.tsx +0 -244
  207. package/src/client/theme/ui/OnThisPage/index.ts +0 -1
  208. package/src/client/theme/ui/OnThisPage/toc.css +0 -152
  209. package/src/client/theme/ui/PoweredBy/PoweredBy.tsx +0 -18
  210. package/src/client/theme/ui/PoweredBy/index.ts +0 -1
  211. package/src/client/theme/ui/PoweredBy/powered-by.css +0 -76
  212. package/src/client/theme/ui/ProgressBar/ProgressBar.css +0 -17
  213. package/src/client/theme/ui/ProgressBar/ProgressBar.tsx +0 -51
  214. package/src/client/theme/ui/ProgressBar/index.ts +0 -1
  215. package/src/client/theme/ui/SearchDialog/SearchDialog.tsx +0 -209
  216. package/src/client/theme/ui/SearchDialog/index.ts +0 -1
  217. package/src/client/theme/ui/SearchDialog/search.css +0 -152
  218. package/src/client/theme/ui/Sidebar/Sidebar.tsx +0 -244
  219. package/src/client/theme/ui/Sidebar/index.ts +0 -1
  220. package/src/client/theme/ui/Sidebar/sidebar.css +0 -230
  221. package/src/client/theme/ui/ThemeToggle/ThemeToggle.tsx +0 -69
  222. package/src/client/theme/ui/ThemeToggle/index.ts +0 -1
  223. package/src/client/theme/ui/VersionSwitcher/VersionSwitcher.tsx +0 -136
  224. package/src/client/theme/ui/VersionSwitcher/index.ts +0 -1
  225. package/src/client/utils.ts +0 -49
@@ -1,762 +0,0 @@
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"?>
384
- <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 `
486
- import { createBoltdocsApp as _createApp } from 'boltdocs/client';
487
- import 'boltdocs/style.css';
488
- ${customCssImport}
489
- import _routes from 'virtual:boltdocs-routes';
490
- import _config from 'virtual:boltdocs-config';
491
- ${homeImport}
492
- ${componentImports}
493
-
494
- _createApp({
495
- target: '#root',
496
- routes: _routes,
497
- docsDirName: '${docsDirName}',
498
- config: _config,
499
- modules: import.meta.glob('/${docsDirName}/**/*.{md,mdx}'),
500
- hot: import.meta.hot,
501
- ${homeOption}
502
- components: { ${componentMap} },
503
- });
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 = `
522
- <script>
523
- (function() {
524
- try {
525
- var stored = localStorage.getItem("boltdocs-theme");
526
- var theme = stored || (window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
527
- if (theme === "light") {
528
- document.documentElement.classList.add("theme-light");
529
- document.documentElement.dataset.theme = "light";
530
- } else {
531
- document.documentElement.classList.remove("theme-light");
532
- document.documentElement.dataset.theme = "dark";
533
- }
534
- } catch (e) {}
535
- })();
536
- </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
- };