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.
- package/dist/{cache-EHR7SXRU.mjs → cache-GQHF6BXI.mjs} +1 -1
- package/dist/{chunk-GSYECEZY.mjs → chunk-CYBWLFOG.mjs} +5 -1
- package/dist/node/index.js +36 -20
- package/dist/node/index.mjs +34 -22
- package/package.json +1 -1
- package/src/client/app/index.tsx +344 -344
- package/src/client/app/preload.tsx +56 -56
- package/src/client/index.ts +40 -40
- package/src/client/ssr.tsx +51 -51
- package/src/client/theme/components/CodeBlock/CodeBlock.tsx +76 -76
- package/src/client/theme/components/CodeBlock/index.ts +1 -1
- package/src/client/theme/components/PackageManagerTabs/PackageManagerTabs.tsx +154 -154
- package/src/client/theme/components/PackageManagerTabs/index.ts +1 -1
- package/src/client/theme/components/PackageManagerTabs/pkg-tabs.css +64 -64
- package/src/client/theme/components/Playground/Playground.tsx +124 -124
- package/src/client/theme/components/Playground/index.ts +1 -1
- package/src/client/theme/components/Playground/playground.css +168 -168
- package/src/client/theme/components/Video/Video.tsx +84 -84
- package/src/client/theme/components/Video/index.ts +1 -1
- package/src/client/theme/components/Video/video.css +41 -41
- package/src/client/theme/components/mdx/Admonition.tsx +80 -80
- package/src/client/theme/components/mdx/Badge.tsx +31 -31
- package/src/client/theme/components/mdx/Button.tsx +50 -50
- package/src/client/theme/components/mdx/Card.tsx +80 -80
- package/src/client/theme/components/mdx/List.tsx +57 -57
- package/src/client/theme/components/mdx/Tabs.tsx +94 -94
- package/src/client/theme/components/mdx/index.ts +18 -18
- package/src/client/theme/components/mdx/mdx-components.css +424 -424
- package/src/client/theme/icons/bun.tsx +62 -62
- package/src/client/theme/icons/deno.tsx +20 -20
- package/src/client/theme/icons/discord.tsx +12 -12
- package/src/client/theme/icons/github.tsx +15 -15
- package/src/client/theme/icons/npm.tsx +13 -13
- package/src/client/theme/icons/pnpm.tsx +72 -72
- package/src/client/theme/icons/twitter.tsx +12 -12
- package/src/client/theme/styles/markdown.css +343 -343
- package/src/client/theme/styles/variables.css +162 -162
- package/src/client/theme/styles.css +37 -37
- package/src/client/theme/ui/BackgroundGradient/BackgroundGradient.tsx +10 -10
- package/src/client/theme/ui/BackgroundGradient/index.ts +1 -1
- package/src/client/theme/ui/Breadcrumbs/Breadcrumbs.tsx +68 -68
- package/src/client/theme/ui/Breadcrumbs/index.ts +1 -1
- package/src/client/theme/ui/Footer/footer.css +32 -32
- package/src/client/theme/ui/Head/Head.tsx +69 -69
- package/src/client/theme/ui/Head/index.ts +1 -1
- package/src/client/theme/ui/LanguageSwitcher/LanguageSwitcher.tsx +125 -125
- package/src/client/theme/ui/LanguageSwitcher/index.ts +1 -1
- package/src/client/theme/ui/LanguageSwitcher/language-switcher.css +98 -98
- package/src/client/theme/ui/Layout/Layout.tsx +202 -202
- package/src/client/theme/ui/Layout/base.css +76 -76
- package/src/client/theme/ui/Layout/index.ts +2 -2
- package/src/client/theme/ui/Layout/pagination.css +72 -72
- package/src/client/theme/ui/Layout/responsive.css +36 -36
- package/src/client/theme/ui/Link/Link.tsx +254 -254
- package/src/client/theme/ui/Link/index.ts +2 -2
- package/src/client/theme/ui/Loading/Loading.tsx +10 -10
- package/src/client/theme/ui/Loading/index.ts +1 -1
- package/src/client/theme/ui/Loading/loading.css +30 -30
- package/src/client/theme/ui/Navbar/GithubStars.tsx +27 -27
- package/src/client/theme/ui/Navbar/Navbar.tsx +145 -145
- package/src/client/theme/ui/Navbar/index.ts +2 -2
- package/src/client/theme/ui/Navbar/navbar.css +233 -233
- package/src/client/theme/ui/NotFound/NotFound.tsx +19 -19
- package/src/client/theme/ui/NotFound/index.ts +1 -1
- package/src/client/theme/ui/NotFound/not-found.css +64 -64
- package/src/client/theme/ui/OnThisPage/OnThisPage.tsx +235 -235
- package/src/client/theme/ui/OnThisPage/index.ts +1 -1
- package/src/client/theme/ui/OnThisPage/toc.css +132 -132
- package/src/client/theme/ui/PoweredBy/PoweredBy.tsx +18 -18
- package/src/client/theme/ui/PoweredBy/index.ts +1 -1
- package/src/client/theme/ui/PoweredBy/powered-by.css +76 -76
- package/src/client/theme/ui/SearchDialog/SearchDialog.tsx +199 -199
- package/src/client/theme/ui/SearchDialog/index.ts +1 -1
- package/src/client/theme/ui/SearchDialog/search.css +152 -152
- package/src/client/theme/ui/Sidebar/Sidebar.tsx +204 -204
- package/src/client/theme/ui/Sidebar/index.ts +1 -1
- package/src/client/theme/ui/Sidebar/sidebar.css +236 -236
- package/src/client/theme/ui/ThemeToggle/ThemeToggle.tsx +69 -69
- package/src/client/theme/ui/ThemeToggle/index.ts +1 -1
- package/src/client/theme/ui/VersionSwitcher/VersionSwitcher.tsx +136 -136
- package/src/client/theme/ui/VersionSwitcher/index.ts +1 -1
- package/src/client/types.ts +50 -50
- package/src/client/utils.ts +26 -26
- package/src/node/cache.ts +408 -408
- package/src/node/config.ts +192 -192
- package/src/node/index.ts +21 -21
- package/src/node/mdx.ts +120 -120
- package/src/node/plugin/entry.ts +58 -58
- package/src/node/plugin/html.ts +55 -55
- package/src/node/plugin/index.ts +193 -193
- package/src/node/plugin/types.ts +11 -11
- package/src/node/routes/cache.ts +28 -28
- package/src/node/routes/index.ts +167 -167
- package/src/node/routes/parser.ts +153 -127
- package/src/node/routes/sorter.ts +42 -42
- package/src/node/routes/types.ts +49 -49
- package/src/node/ssg/index.ts +114 -114
- package/src/node/ssg/meta.ts +33 -34
- package/src/node/ssg/options.ts +13 -13
- package/src/node/ssg/sitemap.ts +55 -54
- package/src/node/utils.ts +145 -134
- package/tsconfig.json +20 -20
- 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, "&")
|
|
88
|
-
.replace(/"/g, """)
|
|
89
|
-
.replace(
|
|
90
|
-
.replace(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* @
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return
|
|
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, "&")
|
|
88
|
+
.replace(/"/g, """)
|
|
89
|
+
.replace(/'/g, "'")
|
|
90
|
+
.replace(/</g, "<")
|
|
91
|
+
.replace(/>/g, ">");
|
|
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
|
+
});
|