boltdocs 1.3.0 → 1.3.2

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 (103) hide show
  1. package/dist/{cache-EHR7SXRU.mjs → cache-GQHF6BXI.mjs} +1 -1
  2. package/dist/{chunk-GSYECEZY.mjs → chunk-CYBWLFOG.mjs} +5 -1
  3. package/dist/node/index.js +36 -20
  4. package/dist/node/index.mjs +34 -22
  5. package/package.json +1 -1
  6. package/src/client/app/index.tsx +344 -344
  7. package/src/client/app/preload.tsx +56 -56
  8. package/src/client/index.ts +40 -40
  9. package/src/client/ssr.tsx +51 -51
  10. package/src/client/theme/components/CodeBlock/CodeBlock.tsx +76 -76
  11. package/src/client/theme/components/CodeBlock/index.ts +1 -1
  12. package/src/client/theme/components/PackageManagerTabs/PackageManagerTabs.tsx +154 -154
  13. package/src/client/theme/components/PackageManagerTabs/index.ts +1 -1
  14. package/src/client/theme/components/PackageManagerTabs/pkg-tabs.css +64 -64
  15. package/src/client/theme/components/Playground/Playground.tsx +124 -124
  16. package/src/client/theme/components/Playground/index.ts +1 -1
  17. package/src/client/theme/components/Playground/playground.css +168 -168
  18. package/src/client/theme/components/Video/Video.tsx +84 -84
  19. package/src/client/theme/components/Video/index.ts +1 -1
  20. package/src/client/theme/components/Video/video.css +41 -41
  21. package/src/client/theme/components/mdx/Admonition.tsx +80 -80
  22. package/src/client/theme/components/mdx/Badge.tsx +31 -31
  23. package/src/client/theme/components/mdx/Button.tsx +50 -50
  24. package/src/client/theme/components/mdx/Card.tsx +80 -80
  25. package/src/client/theme/components/mdx/List.tsx +57 -57
  26. package/src/client/theme/components/mdx/Tabs.tsx +94 -94
  27. package/src/client/theme/components/mdx/index.ts +18 -18
  28. package/src/client/theme/components/mdx/mdx-components.css +424 -424
  29. package/src/client/theme/icons/bun.tsx +62 -62
  30. package/src/client/theme/icons/deno.tsx +20 -20
  31. package/src/client/theme/icons/discord.tsx +12 -12
  32. package/src/client/theme/icons/github.tsx +15 -15
  33. package/src/client/theme/icons/npm.tsx +13 -13
  34. package/src/client/theme/icons/pnpm.tsx +72 -72
  35. package/src/client/theme/icons/twitter.tsx +12 -12
  36. package/src/client/theme/styles/markdown.css +343 -343
  37. package/src/client/theme/styles/variables.css +162 -162
  38. package/src/client/theme/styles.css +37 -37
  39. package/src/client/theme/ui/BackgroundGradient/BackgroundGradient.tsx +10 -10
  40. package/src/client/theme/ui/BackgroundGradient/index.ts +1 -1
  41. package/src/client/theme/ui/Breadcrumbs/Breadcrumbs.tsx +68 -68
  42. package/src/client/theme/ui/Breadcrumbs/index.ts +1 -1
  43. package/src/client/theme/ui/Footer/footer.css +32 -32
  44. package/src/client/theme/ui/Head/Head.tsx +69 -69
  45. package/src/client/theme/ui/Head/index.ts +1 -1
  46. package/src/client/theme/ui/LanguageSwitcher/LanguageSwitcher.tsx +125 -125
  47. package/src/client/theme/ui/LanguageSwitcher/index.ts +1 -1
  48. package/src/client/theme/ui/LanguageSwitcher/language-switcher.css +98 -98
  49. package/src/client/theme/ui/Layout/Layout.tsx +202 -202
  50. package/src/client/theme/ui/Layout/base.css +76 -76
  51. package/src/client/theme/ui/Layout/index.ts +2 -2
  52. package/src/client/theme/ui/Layout/pagination.css +72 -72
  53. package/src/client/theme/ui/Layout/responsive.css +36 -36
  54. package/src/client/theme/ui/Link/Link.tsx +254 -254
  55. package/src/client/theme/ui/Link/index.ts +2 -2
  56. package/src/client/theme/ui/Loading/Loading.tsx +10 -10
  57. package/src/client/theme/ui/Loading/index.ts +1 -1
  58. package/src/client/theme/ui/Loading/loading.css +30 -30
  59. package/src/client/theme/ui/Navbar/GithubStars.tsx +27 -27
  60. package/src/client/theme/ui/Navbar/Navbar.tsx +145 -145
  61. package/src/client/theme/ui/Navbar/index.ts +2 -2
  62. package/src/client/theme/ui/Navbar/navbar.css +233 -233
  63. package/src/client/theme/ui/NotFound/NotFound.tsx +19 -19
  64. package/src/client/theme/ui/NotFound/index.ts +1 -1
  65. package/src/client/theme/ui/NotFound/not-found.css +64 -64
  66. package/src/client/theme/ui/OnThisPage/OnThisPage.tsx +235 -235
  67. package/src/client/theme/ui/OnThisPage/index.ts +1 -1
  68. package/src/client/theme/ui/OnThisPage/toc.css +132 -132
  69. package/src/client/theme/ui/PoweredBy/PoweredBy.tsx +18 -18
  70. package/src/client/theme/ui/PoweredBy/index.ts +1 -1
  71. package/src/client/theme/ui/PoweredBy/powered-by.css +76 -76
  72. package/src/client/theme/ui/SearchDialog/SearchDialog.tsx +199 -199
  73. package/src/client/theme/ui/SearchDialog/index.ts +1 -1
  74. package/src/client/theme/ui/SearchDialog/search.css +152 -152
  75. package/src/client/theme/ui/Sidebar/Sidebar.tsx +204 -204
  76. package/src/client/theme/ui/Sidebar/index.ts +1 -1
  77. package/src/client/theme/ui/Sidebar/sidebar.css +236 -236
  78. package/src/client/theme/ui/ThemeToggle/ThemeToggle.tsx +69 -69
  79. package/src/client/theme/ui/ThemeToggle/index.ts +1 -1
  80. package/src/client/theme/ui/VersionSwitcher/VersionSwitcher.tsx +136 -136
  81. package/src/client/theme/ui/VersionSwitcher/index.ts +1 -1
  82. package/src/client/types.ts +50 -50
  83. package/src/client/utils.ts +26 -26
  84. package/src/node/cache.ts +408 -408
  85. package/src/node/config.ts +192 -192
  86. package/src/node/index.ts +21 -21
  87. package/src/node/mdx.ts +120 -120
  88. package/src/node/plugin/entry.ts +58 -58
  89. package/src/node/plugin/html.ts +55 -55
  90. package/src/node/plugin/index.ts +193 -193
  91. package/src/node/plugin/types.ts +11 -11
  92. package/src/node/routes/cache.ts +28 -28
  93. package/src/node/routes/index.ts +167 -167
  94. package/src/node/routes/parser.ts +153 -127
  95. package/src/node/routes/sorter.ts +42 -42
  96. package/src/node/routes/types.ts +49 -49
  97. package/src/node/ssg/index.ts +114 -114
  98. package/src/node/ssg/meta.ts +33 -34
  99. package/src/node/ssg/options.ts +13 -13
  100. package/src/node/ssg/sitemap.ts +55 -54
  101. package/src/node/utils.ts +145 -134
  102. package/tsconfig.json +20 -20
  103. package/tsup.config.ts +22 -22
package/src/node/utils.ts CHANGED
@@ -1,134 +1,145 @@
1
- import fs from "fs";
2
- import matter from "gray-matter";
3
-
4
- /**
5
- * Normalizes a file path by replacing Windows backslashes with forward slashes.
6
- * Ensures consistent path handling across different operating systems.
7
- *
8
- * @param p - The file path to normalize
9
- * @returns The normalized path using forward slashes
10
- */
11
- export function normalizePath(p: string): string {
12
- return p.replace(/\\/g, "/");
13
- }
14
-
15
- /**
16
- * Strips a numeric prefix from a file or directory name (e.g., '1.guide' -> 'guide').
17
- *
18
- * @param name - The name to strip
19
- * @returns The name without the numeric prefix
20
- */
21
- export function stripNumberPrefix(name: string): string {
22
- return name.replace(/^\d+\./, "");
23
- }
24
-
25
- /**
26
- * Extracts the numeric prefix from a file or directory name if it exists.
27
- *
28
- * @param name - The name to parse
29
- * @returns The extracted number, or undefined if none exists
30
- */
31
- export function extractNumberPrefix(name: string): number | undefined {
32
- const match = name.match(/^(\d+)\./);
33
- return match ? parseInt(match[1], 10) : undefined;
34
- }
35
-
36
- /**
37
- * Checks if a given file path points to a Markdown or MDX file.
38
- *
39
- * @param filePath - The path to check
40
- * @returns True if the file ends with .md or .mdx, false otherwise
41
- */
42
- export function isDocFile(filePath: string): boolean {
43
- return /\.mdx?$/.test(filePath);
44
- }
45
-
46
- /**
47
- * Retrieves the modification time (mtime) of a file in milliseconds.
48
- * Useful for caching strategies to detect if a file has changed.
49
- * Returns 0 if the file doesn't exist or cannot be accessed.
50
- *
51
- * @param filePath - The absolute path to the file
52
- * @returns The modification time in milliseconds, or 0 on error
53
- */
54
- export function getFileMtime(filePath: string): number {
55
- try {
56
- return fs.statSync(filePath).mtimeMs;
57
- } catch {
58
- return 0;
59
- }
60
- }
61
-
62
- /**
63
- * Parses frontmatter and markdown content from a file synchronously.
64
- * Uses `gray-matter` for parsing. Returns the parsed data and the remaining markdown content.
65
- *
66
- * @param filePath - The absolute path to the markdown/mdx file
67
- * @returns An object containing the parsed metadata (`data`) and the raw markdown (`content`)
68
- */
69
- export function parseFrontmatter(filePath: string): {
70
- data: Record<string, any>;
71
- content: string;
72
- } {
73
- const raw = fs.readFileSync(filePath, "utf-8");
74
- const { data, content } = matter(raw);
75
- return { data, content };
76
- }
77
-
78
- /**
79
- * Escapes special HTML characters in a string to prevent XSS and ensure
80
- * safe injection into HTML attributes or text content.
81
- *
82
- * @param str - The raw string to escape
83
- * @returns The escaped string
84
- */
85
- export function escapeHtml(str: string): string {
86
- return str
87
- .replace(/&/g, "&amp;")
88
- .replace(/"/g, "&quot;")
89
- .replace(/</g, "&lt;")
90
- .replace(/>/g, "&gt;");
91
- }
92
-
93
- /**
94
- * Converts a file path relative to the `docsDir` into a URL route path.
95
- * Handles removing extensions, converting `index` files to directory roots,
96
- * and ensuring proper slash formatting.
97
- *
98
- * @param relativePath - The file path relative to the documentation source directory (e.g., 'guide/index.md')
99
- * @returns The corresponding route path (e.g., '/guide')
100
- */
101
- export function fileToRoutePath(relativePath: string): string {
102
- // Strip number prefixes from every segment
103
- let cleanedPath = relativePath.split("/").map(stripNumberPrefix).join("/");
104
-
105
- let routePath = cleanedPath.replace(/\.mdx?$/, "");
106
-
107
- // Handle index files directory root
108
- if (routePath === "index" || routePath.endsWith("/index")) {
109
- routePath = routePath.replace(/index$/, "");
110
- }
111
-
112
- // Ensure leading slash
113
- if (!routePath.startsWith("/")) {
114
- routePath = "/" + routePath;
115
- }
116
-
117
- // Remove trailing slash (except for root '/')
118
- if (routePath.length > 1 && routePath.endsWith("/")) {
119
- routePath = routePath.slice(0, -1);
120
- }
121
-
122
- return routePath;
123
- }
124
-
125
- /**
126
- * Capitalizes the first letter of a given string.
127
- * Used primarily for generating default group titles.
128
- *
129
- * @param str - The string to capitalize
130
- * @returns The capitalized string
131
- */
132
- export function capitalize(str: string): string {
133
- return str.charAt(0).toUpperCase() + str.slice(1);
134
- }
1
+ import fs from "fs";
2
+ import matter from "gray-matter";
3
+
4
+ /**
5
+ * Normalizes a file path by replacing Windows backslashes with forward slashes.
6
+ * Ensures consistent path handling across different operating systems.
7
+ *
8
+ * @param p - The file path to normalize
9
+ * @returns The normalized path using forward slashes
10
+ */
11
+ export function normalizePath(p: string): string {
12
+ return p.replace(/\\/g, "/");
13
+ }
14
+
15
+ /**
16
+ * Strips a numeric prefix from a file or directory name (e.g., '1.guide' -> 'guide').
17
+ *
18
+ * @param name - The name to strip
19
+ * @returns The name without the numeric prefix
20
+ */
21
+ export function stripNumberPrefix(name: string): string {
22
+ return name.replace(/^\d+\./, "");
23
+ }
24
+
25
+ /**
26
+ * Extracts the numeric prefix from a file or directory name if it exists.
27
+ *
28
+ * @param name - The name to parse
29
+ * @returns The extracted number, or undefined if none exists
30
+ */
31
+ export function extractNumberPrefix(name: string): number | undefined {
32
+ const match = name.match(/^(\d+)\./);
33
+ return match ? parseInt(match[1], 10) : undefined;
34
+ }
35
+
36
+ /**
37
+ * Checks if a given file path points to a Markdown or MDX file.
38
+ *
39
+ * @param filePath - The path to check
40
+ * @returns True if the file ends with .md or .mdx, false otherwise
41
+ */
42
+ export function isDocFile(filePath: string): boolean {
43
+ return /\.mdx?$/.test(filePath);
44
+ }
45
+
46
+ /**
47
+ * Retrieves the modification time (mtime) of a file in milliseconds.
48
+ * Useful for caching strategies to detect if a file has changed.
49
+ * Returns 0 if the file doesn't exist or cannot be accessed.
50
+ *
51
+ * @param filePath - The absolute path to the file
52
+ * @returns The modification time in milliseconds, or 0 on error
53
+ */
54
+ export function getFileMtime(filePath: string): number {
55
+ try {
56
+ return fs.statSync(filePath).mtimeMs;
57
+ } catch {
58
+ return 0;
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Parses frontmatter and markdown content from a file synchronously.
64
+ * Uses `gray-matter` for parsing. Returns the parsed data and the remaining markdown content.
65
+ *
66
+ * @param filePath - The absolute path to the markdown/mdx file
67
+ * @returns An object containing the parsed metadata (`data`) and the raw markdown (`content`)
68
+ */
69
+ export function parseFrontmatter(filePath: string): {
70
+ data: Record<string, any>;
71
+ content: string;
72
+ } {
73
+ const raw = fs.readFileSync(filePath, "utf-8");
74
+ const { data, content } = matter(raw);
75
+ return { data, content };
76
+ }
77
+
78
+ /**
79
+ * Escapes special HTML characters in a string to prevent XSS and ensure
80
+ * safe injection into HTML attributes or text content.
81
+ *
82
+ * @param str - The raw string to escape
83
+ * @returns The escaped string
84
+ */
85
+ export function escapeHtml(str: string): string {
86
+ return str
87
+ .replace(/&/g, "&amp;")
88
+ .replace(/"/g, "&quot;")
89
+ .replace(/'/g, "&apos;")
90
+ .replace(/</g, "&lt;")
91
+ .replace(/>/g, "&gt;");
92
+ }
93
+
94
+ /**
95
+ * Alias for escapeHtml to be used in XML contexts (like sitemaps).
96
+ *
97
+ * @param str - The raw string to escape
98
+ * @returns The escaped string
99
+ */
100
+ export function escapeXml(str: string): string {
101
+ return escapeHtml(str);
102
+ }
103
+
104
+ /**
105
+ * Converts a file path relative to the `docsDir` into a URL route path.
106
+ * Handles removing extensions, converting `index` files to directory roots,
107
+ * and ensuring proper slash formatting.
108
+ *
109
+ * @param relativePath - The file path relative to the documentation source directory (e.g., 'guide/index.md')
110
+ * @returns The corresponding route path (e.g., '/guide')
111
+ */
112
+ export function fileToRoutePath(relativePath: string): string {
113
+ // Strip number prefixes from every segment
114
+ let cleanedPath = relativePath.split("/").map(stripNumberPrefix).join("/");
115
+
116
+ let routePath = cleanedPath.replace(/\.mdx?$/, "");
117
+
118
+ // Handle index files directory root
119
+ if (routePath === "index" || routePath.endsWith("/index")) {
120
+ routePath = routePath.replace(/index$/, "");
121
+ }
122
+
123
+ // Ensure leading slash
124
+ if (!routePath.startsWith("/")) {
125
+ routePath = "/" + routePath;
126
+ }
127
+
128
+ // Remove trailing slash (except for root '/')
129
+ if (routePath.length > 1 && routePath.endsWith("/")) {
130
+ routePath = routePath.slice(0, -1);
131
+ }
132
+
133
+ return routePath;
134
+ }
135
+
136
+ /**
137
+ * Capitalizes the first letter of a given string.
138
+ * Used primarily for generating default group titles.
139
+ *
140
+ * @param str - The string to capitalize
141
+ * @returns The capitalized string
142
+ */
143
+ export function capitalize(str: string): string {
144
+ return str.charAt(0).toUpperCase() + str.slice(1);
145
+ }
package/tsconfig.json CHANGED
@@ -1,21 +1,21 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ESNext",
5
- "moduleResolution": "Node",
6
- "esModuleInterop": true,
7
- "strict": true,
8
- "skipLibCheck": true,
9
- "jsx": "react-jsx",
10
- "declaration": true,
11
- "outDir": "dist"
12
- },
13
- "include": [
14
- "src"
15
- ],
16
- "exclude": [
17
- "node_modules",
18
- "dist",
19
- "src/node/cli"
20
- ]
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Node",
6
+ "esModuleInterop": true,
7
+ "strict": true,
8
+ "skipLibCheck": true,
9
+ "jsx": "react-jsx",
10
+ "declaration": true,
11
+ "outDir": "dist"
12
+ },
13
+ "include": [
14
+ "src"
15
+ ],
16
+ "exclude": [
17
+ "node_modules",
18
+ "dist",
19
+ "src/node/cli"
20
+ ]
21
21
  }
package/tsup.config.ts CHANGED
@@ -1,22 +1,22 @@
1
- import { defineConfig } from "tsup";
2
-
3
- export default defineConfig({
4
- entry: [
5
- "src/node/index.ts",
6
- "src/node/cli/index.ts",
7
- "src/client/index.ts",
8
- "src/client/ssr.tsx",
9
- ],
10
- format: ["cjs", "esm"],
11
- dts: true,
12
- tsconfig: "./tsconfig.json",
13
- clean: true,
14
- external: [
15
- "vite",
16
- "react",
17
- "react-dom",
18
- "react-router-dom",
19
- "virtual:boltdocs-routes",
20
- "virtual:boltdocs-config",
21
- ],
22
- });
1
+ import { defineConfig } from "tsup";
2
+
3
+ export default defineConfig({
4
+ entry: [
5
+ "src/node/index.ts",
6
+ "src/node/cli/index.ts",
7
+ "src/client/index.ts",
8
+ "src/client/ssr.tsx",
9
+ ],
10
+ format: ["cjs", "esm"],
11
+ dts: true,
12
+ tsconfig: "./tsconfig.json",
13
+ clean: true,
14
+ external: [
15
+ "vite",
16
+ "react",
17
+ "react-dom",
18
+ "react-router-dom",
19
+ "virtual:boltdocs-routes",
20
+ "virtual:boltdocs-config",
21
+ ],
22
+ });