boltdocs 1.3.0 → 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 (101) hide show
  1. package/dist/node/index.js +21 -6
  2. package/dist/node/index.mjs +21 -6
  3. package/package.json +1 -1
  4. package/src/client/app/index.tsx +344 -344
  5. package/src/client/app/preload.tsx +56 -56
  6. package/src/client/index.ts +40 -40
  7. package/src/client/ssr.tsx +51 -51
  8. package/src/client/theme/components/CodeBlock/CodeBlock.tsx +76 -76
  9. package/src/client/theme/components/CodeBlock/index.ts +1 -1
  10. package/src/client/theme/components/PackageManagerTabs/PackageManagerTabs.tsx +154 -154
  11. package/src/client/theme/components/PackageManagerTabs/index.ts +1 -1
  12. package/src/client/theme/components/PackageManagerTabs/pkg-tabs.css +64 -64
  13. package/src/client/theme/components/Playground/Playground.tsx +124 -124
  14. package/src/client/theme/components/Playground/index.ts +1 -1
  15. package/src/client/theme/components/Playground/playground.css +168 -168
  16. package/src/client/theme/components/Video/Video.tsx +84 -84
  17. package/src/client/theme/components/Video/index.ts +1 -1
  18. package/src/client/theme/components/Video/video.css +41 -41
  19. package/src/client/theme/components/mdx/Admonition.tsx +80 -80
  20. package/src/client/theme/components/mdx/Badge.tsx +31 -31
  21. package/src/client/theme/components/mdx/Button.tsx +50 -50
  22. package/src/client/theme/components/mdx/Card.tsx +80 -80
  23. package/src/client/theme/components/mdx/List.tsx +57 -57
  24. package/src/client/theme/components/mdx/Tabs.tsx +94 -94
  25. package/src/client/theme/components/mdx/index.ts +18 -18
  26. package/src/client/theme/components/mdx/mdx-components.css +424 -424
  27. package/src/client/theme/icons/bun.tsx +62 -62
  28. package/src/client/theme/icons/deno.tsx +20 -20
  29. package/src/client/theme/icons/discord.tsx +12 -12
  30. package/src/client/theme/icons/github.tsx +15 -15
  31. package/src/client/theme/icons/npm.tsx +13 -13
  32. package/src/client/theme/icons/pnpm.tsx +72 -72
  33. package/src/client/theme/icons/twitter.tsx +12 -12
  34. package/src/client/theme/styles/markdown.css +343 -343
  35. package/src/client/theme/styles/variables.css +162 -162
  36. package/src/client/theme/styles.css +37 -37
  37. package/src/client/theme/ui/BackgroundGradient/BackgroundGradient.tsx +10 -10
  38. package/src/client/theme/ui/BackgroundGradient/index.ts +1 -1
  39. package/src/client/theme/ui/Breadcrumbs/Breadcrumbs.tsx +68 -68
  40. package/src/client/theme/ui/Breadcrumbs/index.ts +1 -1
  41. package/src/client/theme/ui/Footer/footer.css +32 -32
  42. package/src/client/theme/ui/Head/Head.tsx +69 -69
  43. package/src/client/theme/ui/Head/index.ts +1 -1
  44. package/src/client/theme/ui/LanguageSwitcher/LanguageSwitcher.tsx +125 -125
  45. package/src/client/theme/ui/LanguageSwitcher/index.ts +1 -1
  46. package/src/client/theme/ui/LanguageSwitcher/language-switcher.css +98 -98
  47. package/src/client/theme/ui/Layout/Layout.tsx +202 -202
  48. package/src/client/theme/ui/Layout/base.css +76 -76
  49. package/src/client/theme/ui/Layout/index.ts +2 -2
  50. package/src/client/theme/ui/Layout/pagination.css +72 -72
  51. package/src/client/theme/ui/Layout/responsive.css +36 -36
  52. package/src/client/theme/ui/Link/Link.tsx +254 -254
  53. package/src/client/theme/ui/Link/index.ts +2 -2
  54. package/src/client/theme/ui/Loading/Loading.tsx +10 -10
  55. package/src/client/theme/ui/Loading/index.ts +1 -1
  56. package/src/client/theme/ui/Loading/loading.css +30 -30
  57. package/src/client/theme/ui/Navbar/GithubStars.tsx +27 -27
  58. package/src/client/theme/ui/Navbar/Navbar.tsx +145 -145
  59. package/src/client/theme/ui/Navbar/index.ts +2 -2
  60. package/src/client/theme/ui/Navbar/navbar.css +233 -233
  61. package/src/client/theme/ui/NotFound/NotFound.tsx +19 -19
  62. package/src/client/theme/ui/NotFound/index.ts +1 -1
  63. package/src/client/theme/ui/NotFound/not-found.css +64 -64
  64. package/src/client/theme/ui/OnThisPage/OnThisPage.tsx +235 -235
  65. package/src/client/theme/ui/OnThisPage/index.ts +1 -1
  66. package/src/client/theme/ui/OnThisPage/toc.css +132 -132
  67. package/src/client/theme/ui/PoweredBy/PoweredBy.tsx +18 -18
  68. package/src/client/theme/ui/PoweredBy/index.ts +1 -1
  69. package/src/client/theme/ui/PoweredBy/powered-by.css +76 -76
  70. package/src/client/theme/ui/SearchDialog/SearchDialog.tsx +199 -199
  71. package/src/client/theme/ui/SearchDialog/index.ts +1 -1
  72. package/src/client/theme/ui/SearchDialog/search.css +152 -152
  73. package/src/client/theme/ui/Sidebar/Sidebar.tsx +204 -204
  74. package/src/client/theme/ui/Sidebar/index.ts +1 -1
  75. package/src/client/theme/ui/Sidebar/sidebar.css +236 -236
  76. package/src/client/theme/ui/ThemeToggle/ThemeToggle.tsx +69 -69
  77. package/src/client/theme/ui/ThemeToggle/index.ts +1 -1
  78. package/src/client/theme/ui/VersionSwitcher/VersionSwitcher.tsx +136 -136
  79. package/src/client/theme/ui/VersionSwitcher/index.ts +1 -1
  80. package/src/client/types.ts +50 -50
  81. package/src/client/utils.ts +26 -26
  82. package/src/node/cache.ts +408 -408
  83. package/src/node/config.ts +192 -192
  84. package/src/node/index.ts +21 -21
  85. package/src/node/mdx.ts +120 -120
  86. package/src/node/plugin/entry.ts +58 -58
  87. package/src/node/plugin/html.ts +55 -55
  88. package/src/node/plugin/index.ts +193 -193
  89. package/src/node/plugin/types.ts +11 -11
  90. package/src/node/routes/cache.ts +28 -28
  91. package/src/node/routes/index.ts +167 -167
  92. package/src/node/routes/parser.ts +153 -127
  93. package/src/node/routes/sorter.ts +42 -42
  94. package/src/node/routes/types.ts +49 -49
  95. package/src/node/ssg/index.ts +114 -114
  96. package/src/node/ssg/meta.ts +34 -34
  97. package/src/node/ssg/options.ts +13 -13
  98. package/src/node/ssg/sitemap.ts +54 -54
  99. package/src/node/utils.ts +134 -134
  100. package/tsconfig.json +20 -20
  101. package/tsup.config.ts +22 -22
package/src/node/utils.ts CHANGED
@@ -1,134 +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, "&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, "&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
+ }
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
+ });