boltdocs 1.0.4 → 1.3.1

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 (121) hide show
  1. package/dist/{SearchDialog-R36WKAQ7.mjs → SearchDialog-5EDRACEG.mjs} +1 -1
  2. package/dist/{SearchDialog-PYF3QMYG.css → SearchDialog-X57WPTNN.css} +54 -126
  3. package/dist/cache-EHR7SXRU.mjs +12 -0
  4. package/dist/chunk-GSYECEZY.mjs +381 -0
  5. package/dist/{chunk-TWSRXUFF.mjs → chunk-NS7WHDYA.mjs} +229 -418
  6. package/dist/client/index.css +54 -126
  7. package/dist/client/index.d.mts +5 -4
  8. package/dist/client/index.d.ts +5 -4
  9. package/dist/client/index.js +555 -580
  10. package/dist/client/index.mjs +304 -16
  11. package/dist/client/ssr.css +54 -126
  12. package/dist/client/ssr.js +257 -580
  13. package/dist/client/ssr.mjs +1 -1
  14. package/dist/{config-D2XmHJYe.d.mts → config-BD5ZHz15.d.mts} +7 -0
  15. package/dist/{config-D2XmHJYe.d.ts → config-BD5ZHz15.d.ts} +7 -0
  16. package/dist/node/index.d.mts +2 -2
  17. package/dist/node/index.d.ts +2 -2
  18. package/dist/node/index.js +477 -123
  19. package/dist/node/index.mjs +114 -142
  20. package/package.json +2 -2
  21. package/src/client/app/index.tsx +344 -373
  22. package/src/client/app/preload.tsx +56 -56
  23. package/src/client/index.ts +40 -40
  24. package/src/client/ssr.tsx +51 -51
  25. package/src/client/theme/components/CodeBlock/CodeBlock.tsx +76 -76
  26. package/src/client/theme/components/CodeBlock/index.ts +1 -1
  27. package/src/client/theme/components/PackageManagerTabs/PackageManagerTabs.tsx +154 -154
  28. package/src/client/theme/components/PackageManagerTabs/index.ts +1 -1
  29. package/src/client/theme/components/PackageManagerTabs/pkg-tabs.css +64 -64
  30. package/src/client/theme/components/Playground/Playground.tsx +124 -124
  31. package/src/client/theme/components/Playground/index.ts +1 -1
  32. package/src/client/theme/components/Playground/playground.css +168 -168
  33. package/src/client/theme/components/Video/Video.tsx +84 -84
  34. package/src/client/theme/components/Video/index.ts +1 -1
  35. package/src/client/theme/components/Video/video.css +41 -41
  36. package/src/client/theme/components/mdx/Admonition.tsx +80 -80
  37. package/src/client/theme/components/mdx/Badge.tsx +31 -31
  38. package/src/client/theme/components/mdx/Button.tsx +50 -50
  39. package/src/client/theme/components/mdx/Card.tsx +80 -80
  40. package/src/client/theme/components/mdx/List.tsx +57 -57
  41. package/src/client/theme/components/mdx/Tabs.tsx +94 -94
  42. package/src/client/theme/components/mdx/index.ts +18 -18
  43. package/src/client/theme/components/mdx/mdx-components.css +424 -405
  44. package/src/client/theme/icons/bun.tsx +62 -62
  45. package/src/client/theme/icons/deno.tsx +20 -20
  46. package/src/client/theme/icons/discord.tsx +12 -12
  47. package/src/client/theme/icons/github.tsx +15 -15
  48. package/src/client/theme/icons/npm.tsx +13 -13
  49. package/src/client/theme/icons/pnpm.tsx +72 -72
  50. package/src/client/theme/icons/twitter.tsx +12 -12
  51. package/src/client/theme/styles/markdown.css +343 -343
  52. package/src/client/theme/styles/variables.css +162 -162
  53. package/src/client/theme/styles.css +37 -38
  54. package/src/client/theme/ui/BackgroundGradient/BackgroundGradient.tsx +10 -10
  55. package/src/client/theme/ui/BackgroundGradient/index.ts +1 -1
  56. package/src/client/theme/ui/Breadcrumbs/Breadcrumbs.tsx +68 -68
  57. package/src/client/theme/ui/Breadcrumbs/index.ts +1 -1
  58. package/src/client/theme/ui/Footer/footer.css +32 -32
  59. package/src/client/theme/ui/Head/Head.tsx +69 -69
  60. package/src/client/theme/ui/Head/index.ts +1 -1
  61. package/src/client/theme/ui/LanguageSwitcher/LanguageSwitcher.tsx +125 -125
  62. package/src/client/theme/ui/LanguageSwitcher/index.ts +1 -1
  63. package/src/client/theme/ui/LanguageSwitcher/language-switcher.css +98 -98
  64. package/src/client/theme/ui/Layout/Layout.tsx +202 -213
  65. package/src/client/theme/ui/Layout/base.css +76 -76
  66. package/src/client/theme/ui/Layout/index.ts +2 -2
  67. package/src/client/theme/ui/Layout/pagination.css +72 -72
  68. package/src/client/theme/ui/Layout/responsive.css +36 -40
  69. package/src/client/theme/ui/Link/Link.tsx +254 -202
  70. package/src/client/theme/ui/Link/index.ts +2 -2
  71. package/src/client/theme/ui/Loading/Loading.tsx +10 -10
  72. package/src/client/theme/ui/Loading/index.ts +1 -1
  73. package/src/client/theme/ui/Loading/loading.css +30 -30
  74. package/src/client/theme/ui/Navbar/GithubStars.tsx +27 -27
  75. package/src/client/theme/ui/Navbar/Navbar.tsx +145 -145
  76. package/src/client/theme/ui/Navbar/index.ts +2 -2
  77. package/src/client/theme/ui/Navbar/navbar.css +233 -233
  78. package/src/client/theme/ui/NotFound/NotFound.tsx +19 -20
  79. package/src/client/theme/ui/NotFound/index.ts +1 -1
  80. package/src/client/theme/ui/NotFound/not-found.css +64 -64
  81. package/src/client/theme/ui/OnThisPage/OnThisPage.tsx +235 -192
  82. package/src/client/theme/ui/OnThisPage/index.ts +1 -1
  83. package/src/client/theme/ui/OnThisPage/toc.css +132 -132
  84. package/src/client/theme/ui/PoweredBy/PoweredBy.tsx +18 -18
  85. package/src/client/theme/ui/PoweredBy/index.ts +1 -1
  86. package/src/client/theme/ui/PoweredBy/powered-by.css +76 -76
  87. package/src/client/theme/ui/SearchDialog/SearchDialog.tsx +199 -199
  88. package/src/client/theme/ui/SearchDialog/index.ts +1 -1
  89. package/src/client/theme/ui/SearchDialog/search.css +152 -152
  90. package/src/client/theme/ui/Sidebar/Sidebar.tsx +204 -200
  91. package/src/client/theme/ui/Sidebar/index.ts +1 -1
  92. package/src/client/theme/ui/Sidebar/sidebar.css +236 -269
  93. package/src/client/theme/ui/ThemeToggle/ThemeToggle.tsx +69 -69
  94. package/src/client/theme/ui/ThemeToggle/index.ts +1 -1
  95. package/src/client/theme/ui/VersionSwitcher/VersionSwitcher.tsx +136 -136
  96. package/src/client/theme/ui/VersionSwitcher/index.ts +1 -1
  97. package/src/client/types.ts +50 -50
  98. package/src/client/utils.ts +26 -26
  99. package/src/node/cache.ts +408 -94
  100. package/src/node/config.ts +192 -185
  101. package/src/node/index.ts +21 -21
  102. package/src/node/mdx.ts +120 -41
  103. package/src/node/plugin/entry.ts +58 -58
  104. package/src/node/plugin/html.ts +55 -55
  105. package/src/node/plugin/index.ts +193 -190
  106. package/src/node/plugin/types.ts +11 -11
  107. package/src/node/routes/cache.ts +28 -24
  108. package/src/node/routes/index.ts +167 -152
  109. package/src/node/routes/parser.ts +153 -127
  110. package/src/node/routes/sorter.ts +42 -42
  111. package/src/node/routes/types.ts +49 -49
  112. package/src/node/ssg/index.ts +114 -110
  113. package/src/node/ssg/meta.ts +34 -34
  114. package/src/node/ssg/options.ts +13 -13
  115. package/src/node/ssg/sitemap.ts +54 -54
  116. package/src/node/utils.ts +134 -134
  117. package/tsconfig.json +20 -20
  118. package/tsup.config.ts +22 -22
  119. package/dist/Playground-B2FA34BC.mjs +0 -6
  120. package/dist/chunk-WPT4MWTQ.mjs +0 -89
  121. package/src/client/theme/styles/home.css +0 -60
@@ -1,185 +1,192 @@
1
- import path from "path";
2
- import { pathToFileURL } from "url";
3
- import fs from "fs";
4
- import type { Plugin as VitePlugin } from "vite";
5
-
6
- /**
7
- * Represents a single social link in the configuration.
8
- */
9
- export interface BoltdocsSocialLink {
10
- /** Identifier for the icon (e.g., 'github', 'twitter') */
11
- icon: "discord" | "x" | string;
12
- /** The URL the social link points to */
13
- link: string;
14
- }
15
-
16
- /**
17
- * Configuration for the site footer.
18
- */
19
- export interface BoltdocsFooterConfig {
20
- /** Text to display in the footer (HTML is supported) */
21
- text?: string;
22
- }
23
-
24
- /**
25
- * Theme-specific configuration options governing the appearance and navigation of the site.
26
- */
27
- export interface BoltdocsThemeConfig {
28
- /** The global title of the documentation site */
29
- title?: string;
30
- /** The global description of the site (used for SEO) */
31
- description?: string;
32
- /** URL path to the site logo */
33
- logo?: string;
34
- /** Items to display in the top navigation bar */
35
- navbar?: Array<{ text: string; link: string }>;
36
- /** Items to display in the sidebar, organized optionally by group URLs */
37
- sidebar?: Record<string, Array<{ text: string; link: string }>>;
38
- /** Social links to display in the navigation bar */
39
- socialLinks?: BoltdocsSocialLink[];
40
- /** Site footer configuration */
41
- footer?: BoltdocsFooterConfig;
42
- /** Whether to show breadcrumbs navigation (default: true) */
43
- breadcrumbs?: boolean;
44
- /** Path to a custom CSS file that overrides theme variables */
45
- customCss?: string;
46
- /** URL template for 'Edit this page'. Use :path as a placeholder. */
47
- editLink?: string;
48
- /** URL for the 'Community help' link. */
49
- communityHelp?: string;
50
- /** The current version of the project (e.g., 'v2.8.9'). Displayed in the Navbar. */
51
- version?: string;
52
- /** The GitHub repository in the format 'owner/repo' to fetch and display star count. */
53
- githubRepo?: string;
54
- /** Whether to show the 'Powered by LiteDocs' badge in the sidebar (default: true) */
55
- poweredBy?: boolean;
56
- /** Granular layout customization props */
57
- layoutProps?: {
58
- navbar?: any;
59
- sidebar?: any;
60
- toc?: any;
61
- background?: any;
62
- head?: any;
63
- breadcrumbs?: any;
64
- className?: string;
65
- style?: any;
66
- };
67
- }
68
-
69
- /**
70
- * Configuration for internationalization (i18n).
71
- */
72
- export interface BoltdocsI18nConfig {
73
- /** The default locale (e.g., 'en') */
74
- defaultLocale: string;
75
- /** Available locales and their display names (e.g., { en: 'English', es: 'Español' }) */
76
- locales: Record<string, string>;
77
- }
78
-
79
- /**
80
- * Configuration for documentation versioning.
81
- */
82
- export interface BoltdocsVersionsConfig {
83
- /** The default version (e.g., 'v2') */
84
- defaultVersion: string;
85
- /** Available versions and their display names (e.g., { v1: 'Version 1.x', v2: 'Version 2.x' }) */
86
- versions: Record<string, string>;
87
- }
88
-
89
- /**
90
- * Defines a Boltdocs plugin that can extend the build process and client-side functionality.
91
- */
92
- export interface BoltdocsPlugin {
93
- /** A unique name for the plugin */
94
- name: string;
95
- /** Whether to run this plugin before or after default ones (optional) */
96
- enforce?: "pre" | "post";
97
- /** Optional remark plugins to add to the MDX pipeline */
98
- remarkPlugins?: any[];
99
- /** Optional rehype plugins to add to the MDX pipeline */
100
- rehypePlugins?: any[];
101
- /** Optional Vite plugins to inject into the build process */
102
- vitePlugins?: VitePlugin[];
103
- /** Optional custom React components to register in MDX. Map of Name -> Module Path. */
104
- components?: Record<string, string>;
105
- }
106
-
107
- /**
108
- * The root configuration object for Boltdocs.
109
- */
110
- export interface BoltdocsConfig {
111
- /** The base URL of the site, used for generating the sitemap */
112
- siteUrl?: string;
113
- /** Configuration pertaining to the UI and appearance */
114
- themeConfig?: BoltdocsThemeConfig;
115
- /** The root directory containing markdown documentation files (default: 'docs') */
116
- docsDir?: string;
117
- /** Configuration for internationalization */
118
- i18n?: BoltdocsI18nConfig;
119
- /** Configuration for documentation versioning */
120
- versions?: BoltdocsVersionsConfig;
121
- /** Custom plugins for extending functionality */
122
- plugins?: BoltdocsPlugin[];
123
- }
124
-
125
- export const CONFIG_FILES = [
126
- "boltdocs.config.js",
127
- "boltdocs.config.mjs",
128
- "boltdocs.config.ts",
129
- ];
130
-
131
- /**
132
- * Loads user's configuration file (e.g., `boltdocs.config.js` or `boltdocs.config.ts`) if it exists,
133
- * merges it with the default configuration, and returns the final `BoltdocsConfig`.
134
- *
135
- * @param docsDir - The fallback/default documentation directory
136
- * @returns A promise resolving to the final merged configuration object
137
- */
138
- export async function resolveConfig(docsDir: string): Promise<BoltdocsConfig> {
139
- const projectRoot = process.cwd();
140
-
141
- const defaults: BoltdocsConfig = {
142
- docsDir: path.resolve(docsDir),
143
- themeConfig: {
144
- title: "Boltdocs",
145
- description: "A Vite documentation framework",
146
- navbar: [
147
- { text: "Home", link: "/" },
148
- { text: "Documentation", link: "/docs" },
149
- ],
150
- },
151
- };
152
-
153
- // Try to load user config
154
- for (const filename of CONFIG_FILES) {
155
- const configPath = path.resolve(projectRoot, filename);
156
- if (fs.existsSync(configPath)) {
157
- try {
158
- // Add a timestamp query parameter to bust the ESM cache
159
- const fileUrl = pathToFileURL(configPath).href + "?t=" + Date.now();
160
- const mod = await import(fileUrl);
161
- const userConfig = mod.default || mod;
162
-
163
- // Merge user themeConfig into defaults
164
- // Support new format where user exports BoltdocsConfig directly
165
- const userThemeConfig = userConfig.themeConfig || userConfig;
166
-
167
- return {
168
- docsDir: path.resolve(docsDir),
169
- themeConfig: {
170
- ...defaults.themeConfig,
171
- ...userThemeConfig,
172
- },
173
- i18n: userConfig.i18n,
174
- versions: userConfig.versions,
175
- siteUrl: userConfig.siteUrl,
176
- plugins: userConfig.plugins || [],
177
- };
178
- } catch (e) {
179
- console.warn(`[boltdocs] Failed to load config from ${filename}:`, e);
180
- }
181
- }
182
- }
183
-
184
- return defaults;
185
- }
1
+ import path from "path";
2
+ import { pathToFileURL } from "url";
3
+ import fs from "fs";
4
+ import type { Plugin as VitePlugin } from "vite";
5
+
6
+ /**
7
+ * Represents a single social link in the configuration.
8
+ */
9
+ export interface BoltdocsSocialLink {
10
+ /** Identifier for the icon (e.g., 'github', 'twitter') */
11
+ icon: "discord" | "x" | string;
12
+ /** The URL the social link points to */
13
+ link: string;
14
+ }
15
+
16
+ /**
17
+ * Configuration for the site footer.
18
+ */
19
+ export interface BoltdocsFooterConfig {
20
+ /** Text to display in the footer (HTML is supported) */
21
+ text?: string;
22
+ }
23
+
24
+ /**
25
+ * Theme-specific configuration options governing the appearance and navigation of the site.
26
+ */
27
+ export interface BoltdocsThemeConfig {
28
+ /** The global title of the documentation site */
29
+ title?: string;
30
+ /** The global description of the site (used for SEO) */
31
+ description?: string;
32
+ /** URL path to the site logo */
33
+ logo?: string;
34
+ /** Items to display in the top navigation bar */
35
+ navbar?: Array<{ text: string; link: string }>;
36
+ /** Items to display in the sidebar, organized optionally by group URLs */
37
+ sidebar?: Record<string, Array<{ text: string; link: string }>>;
38
+ /** Social links to display in the navigation bar */
39
+ socialLinks?: BoltdocsSocialLink[];
40
+ /** Site footer configuration */
41
+ footer?: BoltdocsFooterConfig;
42
+ /** Whether to show breadcrumbs navigation (default: true) */
43
+ breadcrumbs?: boolean;
44
+ /** Path to a custom CSS file that overrides theme variables */
45
+ customCss?: string;
46
+ /** URL template for 'Edit this page'. Use :path as a placeholder. */
47
+ editLink?: string;
48
+ /** URL for the 'Community help' link. */
49
+ communityHelp?: string;
50
+ /** The current version of the project (e.g., 'v2.8.9'). Displayed in the Navbar. */
51
+ version?: string;
52
+ /** The GitHub repository in the format 'owner/repo' to fetch and display star count. */
53
+ githubRepo?: string;
54
+ /** Whether to show the 'Powered by LiteDocs' badge in the sidebar (default: true) */
55
+ poweredBy?: boolean;
56
+ /** Granular layout customization props */
57
+ layoutProps?: {
58
+ navbar?: any;
59
+ sidebar?: any;
60
+ toc?: any;
61
+ background?: any;
62
+ head?: any;
63
+ breadcrumbs?: any;
64
+ className?: string;
65
+ style?: any;
66
+ };
67
+ /**
68
+ * The syntax highlighting theme for code blocks.
69
+ * Supports any Shiki theme name (e.g., 'github-dark', 'one-dark-pro', 'aurora-x').
70
+ * Can also be an object for multiple themes (e.g., { light: 'github-light', dark: 'github-dark' }).
71
+ * Default: 'one-dark-pro'
72
+ */
73
+ codeTheme?: string | Record<string, string>;
74
+ }
75
+
76
+ /**
77
+ * Configuration for internationalization (i18n).
78
+ */
79
+ export interface BoltdocsI18nConfig {
80
+ /** The default locale (e.g., 'en') */
81
+ defaultLocale: string;
82
+ /** Available locales and their display names (e.g., { en: 'English', es: 'Español' }) */
83
+ locales: Record<string, string>;
84
+ }
85
+
86
+ /**
87
+ * Configuration for documentation versioning.
88
+ */
89
+ export interface BoltdocsVersionsConfig {
90
+ /** The default version (e.g., 'v2') */
91
+ defaultVersion: string;
92
+ /** Available versions and their display names (e.g., { v1: 'Version 1.x', v2: 'Version 2.x' }) */
93
+ versions: Record<string, string>;
94
+ }
95
+
96
+ /**
97
+ * Defines a Boltdocs plugin that can extend the build process and client-side functionality.
98
+ */
99
+ export interface BoltdocsPlugin {
100
+ /** A unique name for the plugin */
101
+ name: string;
102
+ /** Whether to run this plugin before or after default ones (optional) */
103
+ enforce?: "pre" | "post";
104
+ /** Optional remark plugins to add to the MDX pipeline */
105
+ remarkPlugins?: any[];
106
+ /** Optional rehype plugins to add to the MDX pipeline */
107
+ rehypePlugins?: any[];
108
+ /** Optional Vite plugins to inject into the build process */
109
+ vitePlugins?: VitePlugin[];
110
+ /** Optional custom React components to register in MDX. Map of Name -> Module Path. */
111
+ components?: Record<string, string>;
112
+ }
113
+
114
+ /**
115
+ * The root configuration object for Boltdocs.
116
+ */
117
+ export interface BoltdocsConfig {
118
+ /** The base URL of the site, used for generating the sitemap */
119
+ siteUrl?: string;
120
+ /** Configuration pertaining to the UI and appearance */
121
+ themeConfig?: BoltdocsThemeConfig;
122
+ /** The root directory containing markdown documentation files (default: 'docs') */
123
+ docsDir?: string;
124
+ /** Configuration for internationalization */
125
+ i18n?: BoltdocsI18nConfig;
126
+ /** Configuration for documentation versioning */
127
+ versions?: BoltdocsVersionsConfig;
128
+ /** Custom plugins for extending functionality */
129
+ plugins?: BoltdocsPlugin[];
130
+ }
131
+
132
+ export const CONFIG_FILES = [
133
+ "boltdocs.config.js",
134
+ "boltdocs.config.mjs",
135
+ "boltdocs.config.ts",
136
+ ];
137
+
138
+ /**
139
+ * Loads user's configuration file (e.g., `boltdocs.config.js` or `boltdocs.config.ts`) if it exists,
140
+ * merges it with the default configuration, and returns the final `BoltdocsConfig`.
141
+ *
142
+ * @param docsDir - The fallback/default documentation directory
143
+ * @returns A promise resolving to the final merged configuration object
144
+ */
145
+ export async function resolveConfig(docsDir: string): Promise<BoltdocsConfig> {
146
+ const projectRoot = process.cwd();
147
+
148
+ const defaults: BoltdocsConfig = {
149
+ docsDir: path.resolve(docsDir),
150
+ themeConfig: {
151
+ title: "Boltdocs",
152
+ description: "A Vite documentation framework",
153
+ navbar: [
154
+ { text: "Home", link: "/" },
155
+ { text: "Documentation", link: "/docs" },
156
+ ],
157
+ },
158
+ };
159
+
160
+ // Try to load user config
161
+ for (const filename of CONFIG_FILES) {
162
+ const configPath = path.resolve(projectRoot, filename);
163
+ if (fs.existsSync(configPath)) {
164
+ try {
165
+ // Add a timestamp query parameter to bust the ESM cache
166
+ const fileUrl = pathToFileURL(configPath).href + "?t=" + Date.now();
167
+ const mod = await import(fileUrl);
168
+ const userConfig = mod.default || mod;
169
+
170
+ // Merge user themeConfig into defaults
171
+ // Support new format where user exports BoltdocsConfig directly
172
+ const userThemeConfig = userConfig.themeConfig || userConfig;
173
+
174
+ return {
175
+ docsDir: path.resolve(docsDir),
176
+ themeConfig: {
177
+ ...defaults.themeConfig,
178
+ ...userThemeConfig,
179
+ },
180
+ i18n: userConfig.i18n,
181
+ versions: userConfig.versions,
182
+ siteUrl: userConfig.siteUrl,
183
+ plugins: userConfig.plugins || [],
184
+ };
185
+ } catch (e) {
186
+ console.warn(`[boltdocs] Failed to load config from ${filename}:`, e);
187
+ }
188
+ }
189
+ }
190
+
191
+ return defaults;
192
+ }
package/src/node/index.ts CHANGED
@@ -1,21 +1,21 @@
1
- import { Plugin } from "vite";
2
- import { boltdocsPlugin } from "./plugin/index";
3
- import { boltdocsMdxPlugin } from "./mdx";
4
- import { BoltdocsPluginOptions } from "./plugin/index";
5
-
6
- import { resolveConfig } from "./config";
7
-
8
- export default async function boltdocs(
9
- options?: BoltdocsPluginOptions,
10
- ): Promise<Plugin[]> {
11
- const docsDir = options?.docsDir || "docs";
12
- const config = await resolveConfig(docsDir);
13
-
14
- return [...boltdocsPlugin(options, config), boltdocsMdxPlugin(config)];
15
- }
16
-
17
- export type { BoltdocsPluginOptions };
18
- export { generateStaticPages } from "./ssg";
19
- export type { SSGOptions } from "./ssg";
20
- export type { RouteMeta } from "./routes";
21
- export type { BoltdocsConfig, BoltdocsThemeConfig } from "./config";
1
+ import { Plugin } from "vite";
2
+ import { boltdocsPlugin } from "./plugin/index";
3
+ import { boltdocsMdxPlugin } from "./mdx";
4
+ import { BoltdocsPluginOptions } from "./plugin/index";
5
+
6
+ import { resolveConfig } from "./config";
7
+
8
+ export default async function boltdocs(
9
+ options?: BoltdocsPluginOptions,
10
+ ): Promise<Plugin[]> {
11
+ const docsDir = options?.docsDir || "docs";
12
+ const config = await resolveConfig(docsDir);
13
+
14
+ return [...boltdocsPlugin(options, config), boltdocsMdxPlugin(config)];
15
+ }
16
+
17
+ export type { BoltdocsPluginOptions };
18
+ export { generateStaticPages } from "./ssg";
19
+ export type { SSGOptions } from "./ssg";
20
+ export type { RouteMeta } from "./routes";
21
+ export type { BoltdocsConfig, BoltdocsThemeConfig } from "./config";
package/src/node/mdx.ts CHANGED
@@ -1,41 +1,120 @@
1
- import mdxPlugin from "@mdx-js/rollup";
2
- import remarkGfm from "remark-gfm";
3
- import remarkFrontmatter from "remark-frontmatter";
4
- import rehypeSlug from "rehype-slug";
5
- import rehypePrettyCode from "rehype-pretty-code";
6
- import type { Plugin } from "vite";
7
-
8
- import type { BoltdocsConfig } from "./config";
9
-
10
- /**
11
- * Configures the MDX compiler for Vite using `@mdx-js/rollup`.
12
- * Includes standard remark and rehype plugins for GitHub Flavored Markdown (GFM),
13
- * frontmatter extraction, auto-linking headers, and syntax highlighting via `rehype-pretty-code`.
14
- *
15
- * @param config - The Boltdocs configuration containing custom plugins
16
- * @returns A Vite plugin configured for MDX parsing
17
- */
18
- export function boltdocsMdxPlugin(config?: BoltdocsConfig): Plugin {
19
- const extraRemarkPlugins =
20
- config?.plugins?.flatMap((p) => p.remarkPlugins || []) || [];
21
- const extraRehypePlugins =
22
- config?.plugins?.flatMap((p) => p.rehypePlugins || []) || [];
23
-
24
- return mdxPlugin({
25
- remarkPlugins: [remarkGfm, remarkFrontmatter, ...extraRemarkPlugins],
26
- rehypePlugins: [
27
- rehypeSlug,
28
- ...extraRehypePlugins,
29
- [
30
- rehypePrettyCode,
31
- {
32
- theme: "one-dark-pro",
33
- keepBackground: false,
34
- },
35
- ],
36
- ],
37
- // Provide React as default for JSX
38
- jsxRuntime: "automatic",
39
- providerImportSource: "@mdx-js/react",
40
- }) as Plugin;
41
- }
1
+ import mdxPlugin from "@mdx-js/rollup";
2
+ import remarkGfm from "remark-gfm";
3
+ import remarkFrontmatter from "remark-frontmatter";
4
+ import rehypeSlug from "rehype-slug";
5
+ import rehypePrettyCode from "rehype-pretty-code";
6
+ import type { Plugin } from "vite";
7
+ import crypto from "crypto";
8
+
9
+ import type { BoltdocsConfig } from "./config";
10
+ import { TransformCache } from "./cache";
11
+
12
+ /**
13
+ * Persistent cache for MDX transformations.
14
+ * Saves results to `.boltdocs/transform-mdx.json.gz`.
15
+ */
16
+ const mdxCache = new TransformCache("mdx");
17
+ let mdxCacheLoaded = false;
18
+
19
+ /**
20
+ * Configures the MDX compiler for Vite using `@mdx-js/rollup`.
21
+ * Includes standard remark and rehype plugins for GitHub Flavored Markdown (GFM),
22
+ * frontmatter extraction, auto-linking headers, and syntax highlighting via `rehype-pretty-code`.
23
+ *
24
+ * Also wraps the plugin with a persistent cache to avoid re-compiling unchanged MDX files.
25
+ *
26
+ * @param config - The Boltdocs configuration containing custom plugins
27
+ * @returns A Vite plugin configured for MDX parsing with caching
28
+ */
29
+ export function boltdocsMdxPlugin(config?: BoltdocsConfig): Plugin {
30
+ const extraRemarkPlugins =
31
+ config?.plugins?.flatMap((p) => p.remarkPlugins || []) || [];
32
+ const extraRehypePlugins =
33
+ config?.plugins?.flatMap((p) => p.rehypePlugins || []) || [];
34
+
35
+ const baseMdxPlugin = mdxPlugin({
36
+ remarkPlugins: [remarkGfm, remarkFrontmatter, ...extraRemarkPlugins],
37
+ rehypePlugins: [
38
+ rehypeSlug,
39
+ ...extraRehypePlugins,
40
+ [
41
+ rehypePrettyCode,
42
+ {
43
+ theme: config?.themeConfig?.codeTheme || "one-dark-pro",
44
+ keepBackground: false,
45
+ },
46
+ ],
47
+ ],
48
+ jsxRuntime: "automatic",
49
+ providerImportSource: "@mdx-js/react",
50
+ }) as Plugin;
51
+
52
+ return {
53
+ ...baseMdxPlugin,
54
+ name: "vite-plugin-boltdocs-mdx",
55
+
56
+ async buildStart() {
57
+ hits = 0;
58
+ total = 0;
59
+ if (!mdxCacheLoaded) {
60
+ mdxCache.load();
61
+ mdxCacheLoaded = true;
62
+ }
63
+ if (baseMdxPlugin.buildStart) {
64
+ await (baseMdxPlugin.buildStart as any).call(this);
65
+ }
66
+ },
67
+
68
+ async transform(code, id, options) {
69
+ if (!id.endsWith(".md") && !id.endsWith(".mdx")) {
70
+ return (baseMdxPlugin.transform as any)?.call(this, code, id, options);
71
+ }
72
+
73
+ total++;
74
+ // Create a cache key based on path, content, and config (simplified)
75
+ const contentHash = crypto.createHash("md5").update(code).digest("hex");
76
+ const cacheKey = `${id}:${contentHash}`;
77
+
78
+ const cached = mdxCache.get(cacheKey);
79
+ if (cached) {
80
+ hits++;
81
+ return { code: cached, map: null };
82
+ }
83
+
84
+ const result = await (baseMdxPlugin.transform as any).call(
85
+ this,
86
+ code,
87
+ id,
88
+ options,
89
+ );
90
+
91
+ if (result && typeof result === "object" && result.code) {
92
+ mdxCache.set(cacheKey, result.code);
93
+ } else if (typeof result === "string") {
94
+ mdxCache.set(cacheKey, result);
95
+ }
96
+
97
+ return result;
98
+ },
99
+
100
+ async buildEnd() {
101
+ mdxCache.save();
102
+ await mdxCache.flush(); // Use instance flush or global flushCache
103
+ if (baseMdxPlugin.buildEnd) {
104
+ await (baseMdxPlugin.buildEnd as any).call(this);
105
+ }
106
+ },
107
+ };
108
+ }
109
+
110
+ /**
111
+ * Returns the current MDX cache statistics.
112
+ * @returns An object with total and hit counts
113
+ * @deprecated Removed for performance
114
+ */
115
+ export function getMdxCacheStats() {
116
+ return { hits: 0, total: 0 };
117
+ }
118
+
119
+ let hits = 0;
120
+ let total = 0;