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.
- package/dist/{SearchDialog-R36WKAQ7.mjs → SearchDialog-5EDRACEG.mjs} +1 -1
- package/dist/{SearchDialog-PYF3QMYG.css → SearchDialog-X57WPTNN.css} +54 -126
- package/dist/cache-EHR7SXRU.mjs +12 -0
- package/dist/chunk-GSYECEZY.mjs +381 -0
- package/dist/{chunk-TWSRXUFF.mjs → chunk-NS7WHDYA.mjs} +229 -418
- package/dist/client/index.css +54 -126
- package/dist/client/index.d.mts +5 -4
- package/dist/client/index.d.ts +5 -4
- package/dist/client/index.js +555 -580
- package/dist/client/index.mjs +304 -16
- package/dist/client/ssr.css +54 -126
- package/dist/client/ssr.js +257 -580
- package/dist/client/ssr.mjs +1 -1
- package/dist/{config-D2XmHJYe.d.mts → config-BD5ZHz15.d.mts} +7 -0
- package/dist/{config-D2XmHJYe.d.ts → config-BD5ZHz15.d.ts} +7 -0
- package/dist/node/index.d.mts +2 -2
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.js +477 -123
- package/dist/node/index.mjs +114 -142
- package/package.json +2 -2
- package/src/client/app/index.tsx +344 -373
- 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 -405
- 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 -38
- 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 -213
- 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 -40
- package/src/client/theme/ui/Link/Link.tsx +254 -202
- 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 -20
- 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 -192
- 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 -200
- package/src/client/theme/ui/Sidebar/index.ts +1 -1
- package/src/client/theme/ui/Sidebar/sidebar.css +236 -269
- 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 -94
- package/src/node/config.ts +192 -185
- package/src/node/index.ts +21 -21
- package/src/node/mdx.ts +120 -41
- package/src/node/plugin/entry.ts +58 -58
- package/src/node/plugin/html.ts +55 -55
- package/src/node/plugin/index.ts +193 -190
- package/src/node/plugin/types.ts +11 -11
- package/src/node/routes/cache.ts +28 -24
- package/src/node/routes/index.ts +167 -152
- 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 -110
- package/src/node/ssg/meta.ts +34 -34
- package/src/node/ssg/options.ts +13 -13
- package/src/node/ssg/sitemap.ts +54 -54
- package/src/node/utils.ts +134 -134
- package/tsconfig.json +20 -20
- package/tsup.config.ts +22 -22
- package/dist/Playground-B2FA34BC.mjs +0 -6
- package/dist/chunk-WPT4MWTQ.mjs +0 -89
- package/src/client/theme/styles/home.css +0 -60
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { RouteMeta } from "./types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Sorts an array of generated routes.
|
|
5
|
-
* Ungrouped items come first. Items within the same group are sorted by position, then alphabetically.
|
|
6
|
-
* Groups are sorted relative to each other by their group position, then alphabetically.
|
|
7
|
-
*
|
|
8
|
-
* @param routes - The unsorted routes
|
|
9
|
-
* @returns A new array of sorted routes suitable for sidebar generation
|
|
10
|
-
*/
|
|
11
|
-
export function sortRoutes(routes: RouteMeta[]): RouteMeta[] {
|
|
12
|
-
return routes.sort((a, b) => {
|
|
13
|
-
// Ungrouped first
|
|
14
|
-
if (!a.group && !b.group) return compareByPosition(a, b);
|
|
15
|
-
if (!a.group) return -1;
|
|
16
|
-
if (!b.group) return 1;
|
|
17
|
-
|
|
18
|
-
// Different groups: sort by group position
|
|
19
|
-
if (a.group !== b.group) {
|
|
20
|
-
return compareByGroupPosition(a, b);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Same group: sort by item position
|
|
24
|
-
return compareByPosition(a, b);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function compareByPosition(a: RouteMeta, b: RouteMeta): number {
|
|
29
|
-
if (a.sidebarPosition !== undefined && b.sidebarPosition !== undefined)
|
|
30
|
-
return a.sidebarPosition - b.sidebarPosition;
|
|
31
|
-
if (a.sidebarPosition !== undefined) return -1;
|
|
32
|
-
if (b.sidebarPosition !== undefined) return 1;
|
|
33
|
-
return a.title.localeCompare(b.title);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function compareByGroupPosition(a: RouteMeta, b: RouteMeta): number {
|
|
37
|
-
if (a.groupPosition !== undefined && b.groupPosition !== undefined)
|
|
38
|
-
return a.groupPosition - b.groupPosition;
|
|
39
|
-
if (a.groupPosition !== undefined) return -1;
|
|
40
|
-
if (b.groupPosition !== undefined) return 1;
|
|
41
|
-
return (a.groupTitle || a.group!).localeCompare(b.groupTitle || b.group!);
|
|
42
|
-
}
|
|
1
|
+
import { RouteMeta } from "./types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sorts an array of generated routes.
|
|
5
|
+
* Ungrouped items come first. Items within the same group are sorted by position, then alphabetically.
|
|
6
|
+
* Groups are sorted relative to each other by their group position, then alphabetically.
|
|
7
|
+
*
|
|
8
|
+
* @param routes - The unsorted routes
|
|
9
|
+
* @returns A new array of sorted routes suitable for sidebar generation
|
|
10
|
+
*/
|
|
11
|
+
export function sortRoutes(routes: RouteMeta[]): RouteMeta[] {
|
|
12
|
+
return routes.sort((a, b) => {
|
|
13
|
+
// Ungrouped first
|
|
14
|
+
if (!a.group && !b.group) return compareByPosition(a, b);
|
|
15
|
+
if (!a.group) return -1;
|
|
16
|
+
if (!b.group) return 1;
|
|
17
|
+
|
|
18
|
+
// Different groups: sort by group position
|
|
19
|
+
if (a.group !== b.group) {
|
|
20
|
+
return compareByGroupPosition(a, b);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Same group: sort by item position
|
|
24
|
+
return compareByPosition(a, b);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function compareByPosition(a: RouteMeta, b: RouteMeta): number {
|
|
29
|
+
if (a.sidebarPosition !== undefined && b.sidebarPosition !== undefined)
|
|
30
|
+
return a.sidebarPosition - b.sidebarPosition;
|
|
31
|
+
if (a.sidebarPosition !== undefined) return -1;
|
|
32
|
+
if (b.sidebarPosition !== undefined) return 1;
|
|
33
|
+
return a.title.localeCompare(b.title);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function compareByGroupPosition(a: RouteMeta, b: RouteMeta): number {
|
|
37
|
+
if (a.groupPosition !== undefined && b.groupPosition !== undefined)
|
|
38
|
+
return a.groupPosition - b.groupPosition;
|
|
39
|
+
if (a.groupPosition !== undefined) return -1;
|
|
40
|
+
if (b.groupPosition !== undefined) return 1;
|
|
41
|
+
return (a.groupTitle || a.group!).localeCompare(b.groupTitle || b.group!);
|
|
42
|
+
}
|
package/src/node/routes/types.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Metadata representing a single documentation route.
|
|
3
|
-
* This information is used to build the client-side router and the sidebar navigation.
|
|
4
|
-
*/
|
|
5
|
-
export interface RouteMeta {
|
|
6
|
-
/** The final URL path for the route (e.g., '/docs/guide/start') */
|
|
7
|
-
path: string;
|
|
8
|
-
/** The absolute filesystem path to the source markdown/mdx file */
|
|
9
|
-
componentPath: string;
|
|
10
|
-
/** The title of the page, usually extracted from frontmatter or the filename */
|
|
11
|
-
title: string;
|
|
12
|
-
/** The relative path from the docs directory, used for edit links */
|
|
13
|
-
filePath: string;
|
|
14
|
-
/** Optional description of the page (for SEO/meta tags) */
|
|
15
|
-
description?: string;
|
|
16
|
-
/** Optional explicit position for ordering in the sidebar */
|
|
17
|
-
sidebarPosition?: number;
|
|
18
|
-
/** The group (directory) this route belongs to */
|
|
19
|
-
group?: string;
|
|
20
|
-
/** The display title for the route's group */
|
|
21
|
-
groupTitle?: string;
|
|
22
|
-
/** Optional explicit position for ordering the group itself */
|
|
23
|
-
groupPosition?: number;
|
|
24
|
-
/** Extracted markdown headings for search indexing */
|
|
25
|
-
headings?: { level: number; text: string; id: string }[];
|
|
26
|
-
/** The locale this route belongs to, if i18n is configured */
|
|
27
|
-
locale?: string;
|
|
28
|
-
/** The version this route belongs to, if versioning is configured */
|
|
29
|
-
version?: string;
|
|
30
|
-
/** Optional badge to display next to the sidebar item (e.g., 'New', 'Experimental') */
|
|
31
|
-
badge?: string | { text: string; expires?: string };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Internal representation of a parsed documentation file before finalizing groups.
|
|
36
|
-
* Stored in the file cache to avoid re-parsing unchanged files.
|
|
37
|
-
*/
|
|
38
|
-
export interface ParsedDocFile {
|
|
39
|
-
/** The core route metadata without group-level details (inferred later) */
|
|
40
|
-
route: Omit<RouteMeta, "group" | "groupTitle" | "groupPosition">;
|
|
41
|
-
/** The base directory of the file (used to group files together) */
|
|
42
|
-
relativeDir?: string;
|
|
43
|
-
/** Whether this file is the index file for its directory group */
|
|
44
|
-
isGroupIndex: boolean;
|
|
45
|
-
/** If this is a group index, any specific frontmatter metadata dictating the group's title and position */
|
|
46
|
-
groupMeta?: { title: string; position?: number };
|
|
47
|
-
/** Extracted group position from the directory name if it has a numeric prefix */
|
|
48
|
-
inferredGroupPosition?: number;
|
|
49
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Metadata representing a single documentation route.
|
|
3
|
+
* This information is used to build the client-side router and the sidebar navigation.
|
|
4
|
+
*/
|
|
5
|
+
export interface RouteMeta {
|
|
6
|
+
/** The final URL path for the route (e.g., '/docs/guide/start') */
|
|
7
|
+
path: string;
|
|
8
|
+
/** The absolute filesystem path to the source markdown/mdx file */
|
|
9
|
+
componentPath: string;
|
|
10
|
+
/** The title of the page, usually extracted from frontmatter or the filename */
|
|
11
|
+
title: string;
|
|
12
|
+
/** The relative path from the docs directory, used for edit links */
|
|
13
|
+
filePath: string;
|
|
14
|
+
/** Optional description of the page (for SEO/meta tags) */
|
|
15
|
+
description?: string;
|
|
16
|
+
/** Optional explicit position for ordering in the sidebar */
|
|
17
|
+
sidebarPosition?: number;
|
|
18
|
+
/** The group (directory) this route belongs to */
|
|
19
|
+
group?: string;
|
|
20
|
+
/** The display title for the route's group */
|
|
21
|
+
groupTitle?: string;
|
|
22
|
+
/** Optional explicit position for ordering the group itself */
|
|
23
|
+
groupPosition?: number;
|
|
24
|
+
/** Extracted markdown headings for search indexing */
|
|
25
|
+
headings?: { level: number; text: string; id: string }[];
|
|
26
|
+
/** The locale this route belongs to, if i18n is configured */
|
|
27
|
+
locale?: string;
|
|
28
|
+
/** The version this route belongs to, if versioning is configured */
|
|
29
|
+
version?: string;
|
|
30
|
+
/** Optional badge to display next to the sidebar item (e.g., 'New', 'Experimental') */
|
|
31
|
+
badge?: string | { text: string; expires?: string };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Internal representation of a parsed documentation file before finalizing groups.
|
|
36
|
+
* Stored in the file cache to avoid re-parsing unchanged files.
|
|
37
|
+
*/
|
|
38
|
+
export interface ParsedDocFile {
|
|
39
|
+
/** The core route metadata without group-level details (inferred later) */
|
|
40
|
+
route: Omit<RouteMeta, "group" | "groupTitle" | "groupPosition">;
|
|
41
|
+
/** The base directory of the file (used to group files together) */
|
|
42
|
+
relativeDir?: string;
|
|
43
|
+
/** Whether this file is the index file for its directory group */
|
|
44
|
+
isGroupIndex: boolean;
|
|
45
|
+
/** If this is a group index, any specific frontmatter metadata dictating the group's title and position */
|
|
46
|
+
groupMeta?: { title: string; position?: number };
|
|
47
|
+
/** Extracted group position from the directory name if it has a numeric prefix */
|
|
48
|
+
inferredGroupPosition?: number;
|
|
49
|
+
}
|
package/src/node/ssg/index.ts
CHANGED
|
@@ -1,110 +1,114 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { generateRoutes } from "../routes";
|
|
4
|
-
import { escapeHtml } from "../utils";
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
6
|
-
import { createRequire } from "module";
|
|
7
|
-
|
|
8
|
-
import { SSGOptions } from "./options";
|
|
9
|
-
import { replaceMetaTags } from "./meta";
|
|
10
|
-
import { generateSitemap } from "./sitemap";
|
|
11
|
-
|
|
12
|
-
// Re-export options for consumers
|
|
13
|
-
export type { SSGOptions };
|
|
14
|
-
|
|
15
|
-
// Polyfill __dirname and require for ESM
|
|
16
|
-
const _filename = fileURLToPath(import.meta.url);
|
|
17
|
-
const _dirname = path.dirname(_filename);
|
|
18
|
-
const _require = createRequire(import.meta.url);
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Generates static HTML files and a \`sitemap.xml\` for all documentation routes.
|
|
22
|
-
* Called automatically in the \`closeBundle\` hook of the Vite plugin during a production build.
|
|
23
|
-
*
|
|
24
|
-
* @param options - Configuration for paths and site metadata
|
|
25
|
-
*/
|
|
26
|
-
export async function generateStaticPages(options: SSGOptions): Promise<void> {
|
|
27
|
-
const { docsDir, outDir, config } = options;
|
|
28
|
-
const routes = await generateRoutes(docsDir, config);
|
|
29
|
-
const siteTitle = config?.themeConfig?.title || "Boltdocs";
|
|
30
|
-
const siteDescription = config?.themeConfig?.description || "";
|
|
31
|
-
|
|
32
|
-
// Resolve the SSR module (compiled by tsup)
|
|
33
|
-
const ssrModulePath = path.resolve(_dirname, "../client/ssr.js");
|
|
34
|
-
if (!fs.existsSync(ssrModulePath)) {
|
|
35
|
-
console.error(
|
|
36
|
-
"[boltdocs] SSR module not found at",
|
|
37
|
-
ssrModulePath,
|
|
38
|
-
"- Did you build the core package?",
|
|
39
|
-
);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const { render } = _require(ssrModulePath);
|
|
43
|
-
|
|
44
|
-
// Read the built index.html as template
|
|
45
|
-
const templatePath = path.join(outDir, "index.html");
|
|
46
|
-
if (!fs.existsSync(templatePath)) {
|
|
47
|
-
console.warn("[boltdocs] No index.html found in outDir, skipping SSG.");
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const template = fs.readFileSync(templatePath, "utf-8");
|
|
51
|
-
|
|
52
|
-
// Load user's homePage if configured
|
|
53
|
-
let homePageComp;
|
|
54
|
-
if ((config as any)?._homePagePath) {
|
|
55
|
-
try {
|
|
56
|
-
// Simplistic: if there's a custom home page compiled, we'd need it available to SSR.
|
|
57
|
-
// In a full framework this is complex, but for Boltdocs we assume it's bundled if needed.
|
|
58
|
-
} catch (e) {}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Generate an HTML file for each route concurrently
|
|
62
|
-
await Promise.all(
|
|
63
|
-
routes.map(async (route) => {
|
|
64
|
-
const pageTitle = `${route.title} | ${siteTitle}`;
|
|
65
|
-
const pageDescription = route.description || siteDescription;
|
|
66
|
-
|
|
67
|
-
// We mock the modules for SSR so it doesn't crash trying to dynamically import
|
|
68
|
-
const fakeModules: Record<string, any> = {};
|
|
69
|
-
fakeModules[route.componentPath] = { default: () => {} }; // Mock MDX component
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
const appHtml = await render({
|
|
73
|
-
path: route.path,
|
|
74
|
-
routes: routes,
|
|
75
|
-
config: config || {},
|
|
76
|
-
modules: fakeModules,
|
|
77
|
-
homePage: homePageComp,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const html = replaceMetaTags(template, {
|
|
81
|
-
title: escapeHtml(pageTitle),
|
|
82
|
-
description: escapeHtml(pageDescription),
|
|
83
|
-
})
|
|
84
|
-
.replace("<!--app-html-->", appHtml)
|
|
85
|
-
.replace(`<div id="root"></div>`, `<div id="root">${appHtml}</div>`);
|
|
86
|
-
|
|
87
|
-
const routeDir = path.join(outDir, route.path);
|
|
88
|
-
await fs.promises.mkdir(routeDir, { recursive: true });
|
|
89
|
-
await fs.promises.writeFile(
|
|
90
|
-
path.join(routeDir, "index.html"),
|
|
91
|
-
html,
|
|
92
|
-
"utf-8",
|
|
93
|
-
);
|
|
94
|
-
} catch (e) {
|
|
95
|
-
console.error(`[boltdocs] Error SSR rendering route ${route.path}:`, e);
|
|
96
|
-
}
|
|
97
|
-
}),
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
// Generate sitemap.xml
|
|
101
|
-
const sitemap = generateSitemap(
|
|
102
|
-
routes.map((r) => r.path),
|
|
103
|
-
config,
|
|
104
|
-
);
|
|
105
|
-
fs.writeFileSync(path.join(outDir, "sitemap.xml"), sitemap, "utf-8");
|
|
106
|
-
|
|
107
|
-
console.log(
|
|
108
|
-
`[boltdocs] Generated ${routes.length} static pages + sitemap.xml`,
|
|
109
|
-
);
|
|
110
|
-
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { generateRoutes } from "../routes";
|
|
4
|
+
import { escapeHtml } from "../utils";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import { createRequire } from "module";
|
|
7
|
+
|
|
8
|
+
import { SSGOptions } from "./options";
|
|
9
|
+
import { replaceMetaTags } from "./meta";
|
|
10
|
+
import { generateSitemap } from "./sitemap";
|
|
11
|
+
|
|
12
|
+
// Re-export options for consumers
|
|
13
|
+
export type { SSGOptions };
|
|
14
|
+
|
|
15
|
+
// Polyfill __dirname and require for ESM
|
|
16
|
+
const _filename = fileURLToPath(import.meta.url);
|
|
17
|
+
const _dirname = path.dirname(_filename);
|
|
18
|
+
const _require = createRequire(import.meta.url);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Generates static HTML files and a \`sitemap.xml\` for all documentation routes.
|
|
22
|
+
* Called automatically in the \`closeBundle\` hook of the Vite plugin during a production build.
|
|
23
|
+
*
|
|
24
|
+
* @param options - Configuration for paths and site metadata
|
|
25
|
+
*/
|
|
26
|
+
export async function generateStaticPages(options: SSGOptions): Promise<void> {
|
|
27
|
+
const { docsDir, outDir, config } = options;
|
|
28
|
+
const routes = await generateRoutes(docsDir, config);
|
|
29
|
+
const siteTitle = config?.themeConfig?.title || "Boltdocs";
|
|
30
|
+
const siteDescription = config?.themeConfig?.description || "";
|
|
31
|
+
|
|
32
|
+
// Resolve the SSR module (compiled by tsup)
|
|
33
|
+
const ssrModulePath = path.resolve(_dirname, "../client/ssr.js");
|
|
34
|
+
if (!fs.existsSync(ssrModulePath)) {
|
|
35
|
+
console.error(
|
|
36
|
+
"[boltdocs] SSR module not found at",
|
|
37
|
+
ssrModulePath,
|
|
38
|
+
"- Did you build the core package?",
|
|
39
|
+
);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const { render } = _require(ssrModulePath);
|
|
43
|
+
|
|
44
|
+
// Read the built index.html as template
|
|
45
|
+
const templatePath = path.join(outDir, "index.html");
|
|
46
|
+
if (!fs.existsSync(templatePath)) {
|
|
47
|
+
console.warn("[boltdocs] No index.html found in outDir, skipping SSG.");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const template = fs.readFileSync(templatePath, "utf-8");
|
|
51
|
+
|
|
52
|
+
// Load user's homePage if configured
|
|
53
|
+
let homePageComp;
|
|
54
|
+
if ((config as any)?._homePagePath) {
|
|
55
|
+
try {
|
|
56
|
+
// Simplistic: if there's a custom home page compiled, we'd need it available to SSR.
|
|
57
|
+
// In a full framework this is complex, but for Boltdocs we assume it's bundled if needed.
|
|
58
|
+
} catch (e) {}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Generate an HTML file for each route concurrently
|
|
62
|
+
await Promise.all(
|
|
63
|
+
routes.map(async (route) => {
|
|
64
|
+
const pageTitle = `${route.title} | ${siteTitle}`;
|
|
65
|
+
const pageDescription = route.description || siteDescription;
|
|
66
|
+
|
|
67
|
+
// We mock the modules for SSR so it doesn't crash trying to dynamically import
|
|
68
|
+
const fakeModules: Record<string, any> = {};
|
|
69
|
+
fakeModules[route.componentPath] = { default: () => {} }; // Mock MDX component
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const appHtml = await render({
|
|
73
|
+
path: route.path,
|
|
74
|
+
routes: routes,
|
|
75
|
+
config: config || {},
|
|
76
|
+
modules: fakeModules,
|
|
77
|
+
homePage: homePageComp,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const html = replaceMetaTags(template, {
|
|
81
|
+
title: escapeHtml(pageTitle),
|
|
82
|
+
description: escapeHtml(pageDescription),
|
|
83
|
+
})
|
|
84
|
+
.replace("<!--app-html-->", appHtml)
|
|
85
|
+
.replace(`<div id="root"></div>`, `<div id="root">${appHtml}</div>`);
|
|
86
|
+
|
|
87
|
+
const routeDir = path.join(outDir, route.path);
|
|
88
|
+
await fs.promises.mkdir(routeDir, { recursive: true });
|
|
89
|
+
await fs.promises.writeFile(
|
|
90
|
+
path.join(routeDir, "index.html"),
|
|
91
|
+
html,
|
|
92
|
+
"utf-8",
|
|
93
|
+
);
|
|
94
|
+
} catch (e) {
|
|
95
|
+
console.error(`[boltdocs] Error SSR rendering route ${route.path}:`, e);
|
|
96
|
+
}
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// Generate sitemap.xml
|
|
101
|
+
const sitemap = generateSitemap(
|
|
102
|
+
routes.map((r) => r.path),
|
|
103
|
+
config,
|
|
104
|
+
);
|
|
105
|
+
fs.writeFileSync(path.join(outDir, "sitemap.xml"), sitemap, "utf-8");
|
|
106
|
+
|
|
107
|
+
console.log(
|
|
108
|
+
`[boltdocs] Generated ${routes.length} static pages + sitemap.xml`,
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
// Ensure all cache operations (like index persistence) are finished
|
|
112
|
+
const { flushCache } = await import("../cache");
|
|
113
|
+
await flushCache();
|
|
114
|
+
}
|
package/src/node/ssg/meta.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Replaces placeholder or default meta tags in the HTML template with page-specific values.
|
|
3
|
-
*
|
|
4
|
-
* @param html - The base HTML template string
|
|
5
|
-
* @param meta - An object containing the derived `title` and `description` for the specific page
|
|
6
|
-
* @returns The final HTML string for that specific page
|
|
7
|
-
*/
|
|
8
|
-
export function replaceMetaTags(
|
|
9
|
-
html: string,
|
|
10
|
-
meta: { title: string; description: string },
|
|
11
|
-
): string {
|
|
12
|
-
return html
|
|
13
|
-
.replace(/<title>.*?<\/title>/, `<title>${meta.title}</title>`)
|
|
14
|
-
.replace(
|
|
15
|
-
/(<meta name="description" content=")[^"]*(")/,
|
|
16
|
-
`$1${meta.description}$2`,
|
|
17
|
-
)
|
|
18
|
-
.replace(
|
|
19
|
-
/(<meta property="og:title" content=")[^"]*(")/,
|
|
20
|
-
`$1${meta.title}$2`,
|
|
21
|
-
)
|
|
22
|
-
.replace(
|
|
23
|
-
/(<meta property="og:description" content=")[^"]*(")/,
|
|
24
|
-
`$1${meta.description}$2`,
|
|
25
|
-
)
|
|
26
|
-
.replace(
|
|
27
|
-
/(<meta name="twitter:title" content=")[^"]*(")/,
|
|
28
|
-
`$1${meta.title}$2`,
|
|
29
|
-
)
|
|
30
|
-
.replace(
|
|
31
|
-
/(<meta name="twitter:description" content=")[^"]*(")/,
|
|
32
|
-
`$1${meta.description}$2`,
|
|
33
|
-
);
|
|
34
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Replaces placeholder or default meta tags in the HTML template with page-specific values.
|
|
3
|
+
*
|
|
4
|
+
* @param html - The base HTML template string
|
|
5
|
+
* @param meta - An object containing the derived `title` and `description` for the specific page
|
|
6
|
+
* @returns The final HTML string for that specific page
|
|
7
|
+
*/
|
|
8
|
+
export function replaceMetaTags(
|
|
9
|
+
html: string,
|
|
10
|
+
meta: { title: string; description: string },
|
|
11
|
+
): string {
|
|
12
|
+
return html
|
|
13
|
+
.replace(/<title>.*?<\/title>/, `<title>${meta.title}</title>`)
|
|
14
|
+
.replace(
|
|
15
|
+
/(<meta name="description" content=")[^"]*(")/,
|
|
16
|
+
`$1${meta.description}$2`,
|
|
17
|
+
)
|
|
18
|
+
.replace(
|
|
19
|
+
/(<meta property="og:title" content=")[^"]*(")/,
|
|
20
|
+
`$1${meta.title}$2`,
|
|
21
|
+
)
|
|
22
|
+
.replace(
|
|
23
|
+
/(<meta property="og:description" content=")[^"]*(")/,
|
|
24
|
+
`$1${meta.description}$2`,
|
|
25
|
+
)
|
|
26
|
+
.replace(
|
|
27
|
+
/(<meta name="twitter:title" content=")[^"]*(")/,
|
|
28
|
+
`$1${meta.title}$2`,
|
|
29
|
+
)
|
|
30
|
+
.replace(
|
|
31
|
+
/(<meta name="twitter:description" content=")[^"]*(")/,
|
|
32
|
+
`$1${meta.description}$2`,
|
|
33
|
+
);
|
|
34
|
+
}
|
package/src/node/ssg/options.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { BoltdocsConfig } from "../config";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Options for the Static Site Generation process.
|
|
5
|
-
*/
|
|
6
|
-
export interface SSGOptions {
|
|
7
|
-
/** The root directory containing markdown documentation files */
|
|
8
|
-
docsDir: string;
|
|
9
|
-
/** The output directory where Vite placed the compiled `index.html` and assets */
|
|
10
|
-
outDir: string;
|
|
11
|
-
/** Pre-resolved config (avoids re-resolving during the SSG phase) */
|
|
12
|
-
config?: BoltdocsConfig;
|
|
13
|
-
}
|
|
1
|
+
import { BoltdocsConfig } from "../config";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for the Static Site Generation process.
|
|
5
|
+
*/
|
|
6
|
+
export interface SSGOptions {
|
|
7
|
+
/** The root directory containing markdown documentation files */
|
|
8
|
+
docsDir: string;
|
|
9
|
+
/** The output directory where Vite placed the compiled `index.html` and assets */
|
|
10
|
+
outDir: string;
|
|
11
|
+
/** Pre-resolved config (avoids re-resolving during the SSG phase) */
|
|
12
|
+
config?: BoltdocsConfig;
|
|
13
|
+
}
|
package/src/node/ssg/sitemap.ts
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { BoltdocsConfig } from "../config";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Generates a standard XML sitemap for search engine crawlers.
|
|
5
|
-
*
|
|
6
|
-
* @param routePaths - An array of existing URL paths (e.g., ['/docs/intro', '/docs/setup'])
|
|
7
|
-
* @param config - The Boltdocs configuration containing i18n and siteUrl settings
|
|
8
|
-
* @returns The formatted XML sitemap string
|
|
9
|
-
*/
|
|
10
|
-
export function generateSitemap(
|
|
11
|
-
routePaths: string[],
|
|
12
|
-
config?: BoltdocsConfig,
|
|
13
|
-
): string {
|
|
14
|
-
const baseUrl = config?.siteUrl?.replace(/\/$/, "") || "https://example.com";
|
|
15
|
-
const today = new Date().toISOString().split("T")[0];
|
|
16
|
-
|
|
17
|
-
const rootEntries = [{ url: "/", priority: "1.0", changefreq: "daily" }];
|
|
18
|
-
|
|
19
|
-
if (config?.i18n) {
|
|
20
|
-
const defaultLocale = config.i18n.defaultLocale;
|
|
21
|
-
for (const locale of Object.keys(config.i18n.locales)) {
|
|
22
|
-
if (locale !== defaultLocale) {
|
|
23
|
-
rootEntries.push({
|
|
24
|
-
url: `/${locale}/`,
|
|
25
|
-
priority: "1.0",
|
|
26
|
-
changefreq: "daily",
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const entries = [
|
|
33
|
-
...rootEntries,
|
|
34
|
-
...routePaths.map((p) => ({
|
|
35
|
-
url: p,
|
|
36
|
-
priority: "0.8",
|
|
37
|
-
changefreq: "weekly",
|
|
38
|
-
})),
|
|
39
|
-
];
|
|
40
|
-
|
|
41
|
-
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
42
|
-
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
43
|
-
${entries
|
|
44
|
-
.map(
|
|
45
|
-
(e) => ` <url>
|
|
46
|
-
<loc>${baseUrl}${e.url}</loc>
|
|
47
|
-
<lastmod>${today}</lastmod>
|
|
48
|
-
<changefreq>${e.changefreq}</changefreq>
|
|
49
|
-
<priority>${e.priority}</priority>
|
|
50
|
-
</url>`,
|
|
51
|
-
)
|
|
52
|
-
.join("\n")}
|
|
53
|
-
</urlset>`;
|
|
54
|
-
}
|
|
1
|
+
import { BoltdocsConfig } from "../config";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generates a standard XML sitemap for search engine crawlers.
|
|
5
|
+
*
|
|
6
|
+
* @param routePaths - An array of existing URL paths (e.g., ['/docs/intro', '/docs/setup'])
|
|
7
|
+
* @param config - The Boltdocs configuration containing i18n and siteUrl settings
|
|
8
|
+
* @returns The formatted XML sitemap string
|
|
9
|
+
*/
|
|
10
|
+
export function generateSitemap(
|
|
11
|
+
routePaths: string[],
|
|
12
|
+
config?: BoltdocsConfig,
|
|
13
|
+
): string {
|
|
14
|
+
const baseUrl = config?.siteUrl?.replace(/\/$/, "") || "https://example.com";
|
|
15
|
+
const today = new Date().toISOString().split("T")[0];
|
|
16
|
+
|
|
17
|
+
const rootEntries = [{ url: "/", priority: "1.0", changefreq: "daily" }];
|
|
18
|
+
|
|
19
|
+
if (config?.i18n) {
|
|
20
|
+
const defaultLocale = config.i18n.defaultLocale;
|
|
21
|
+
for (const locale of Object.keys(config.i18n.locales)) {
|
|
22
|
+
if (locale !== defaultLocale) {
|
|
23
|
+
rootEntries.push({
|
|
24
|
+
url: `/${locale}/`,
|
|
25
|
+
priority: "1.0",
|
|
26
|
+
changefreq: "daily",
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const entries = [
|
|
33
|
+
...rootEntries,
|
|
34
|
+
...routePaths.map((p) => ({
|
|
35
|
+
url: p,
|
|
36
|
+
priority: "0.8",
|
|
37
|
+
changefreq: "weekly",
|
|
38
|
+
})),
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
42
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
43
|
+
${entries
|
|
44
|
+
.map(
|
|
45
|
+
(e) => ` <url>
|
|
46
|
+
<loc>${baseUrl}${e.url}</loc>
|
|
47
|
+
<lastmod>${today}</lastmod>
|
|
48
|
+
<changefreq>${e.changefreq}</changefreq>
|
|
49
|
+
<priority>${e.priority}</priority>
|
|
50
|
+
</url>`,
|
|
51
|
+
)
|
|
52
|
+
.join("\n")}
|
|
53
|
+
</urlset>`;
|
|
54
|
+
}
|