@marlinjai/clearify 1.5.0
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/LICENSE +21 -0
- package/README.md +81 -0
- package/bin/clearify.js +2 -0
- package/dist/node/chunk-5TD7NQIW.js +25 -0
- package/dist/node/chunk-B2Q23JW3.js +55 -0
- package/dist/node/chunk-CQ4MNGBE.js +301 -0
- package/dist/node/chunk-GFD54GNO.js +223 -0
- package/dist/node/chunk-IBK35HZR.js +194 -0
- package/dist/node/chunk-L24ILRSX.js +125 -0
- package/dist/node/chunk-NXQNNLGC.js +395 -0
- package/dist/node/chunk-PRTER35L.js +48 -0
- package/dist/node/chunk-SCZZB7OE.js +9 -0
- package/dist/node/chunk-V7LLYIRO.js +8 -0
- package/dist/node/chunk-WT5W333R.js +136 -0
- package/dist/node/cli/index.d.ts +2 -0
- package/dist/node/cli/index.js +41 -0
- package/dist/node/core/config.d.ts +9 -0
- package/dist/node/core/config.js +16 -0
- package/dist/node/core/mermaid-renderer.d.ts +22 -0
- package/dist/node/core/mermaid-renderer.js +125 -0
- package/dist/node/core/mermaid-utils.d.ts +3 -0
- package/dist/node/core/mermaid-utils.js +6 -0
- package/dist/node/core/navigation.d.ts +2 -0
- package/dist/node/core/navigation.js +13 -0
- package/dist/node/core/openapi-parser.d.ts +14 -0
- package/dist/node/core/openapi-parser.js +6 -0
- package/dist/node/core/remark-mermaid.d.ts +10 -0
- package/dist/node/core/remark-mermaid.js +11 -0
- package/dist/node/core/search.d.ts +31 -0
- package/dist/node/core/search.js +6 -0
- package/dist/node/node/build.d.ts +3 -0
- package/dist/node/node/build.js +14 -0
- package/dist/node/node/check.d.ts +3 -0
- package/dist/node/node/check.js +10 -0
- package/dist/node/node/index.d.ts +11 -0
- package/dist/node/node/index.js +108 -0
- package/dist/node/node/init.d.ts +6 -0
- package/dist/node/node/init.js +6 -0
- package/dist/node/presets/nestjs.d.ts +15 -0
- package/dist/node/presets/nestjs.js +98 -0
- package/dist/node/types/index.d.ts +79 -0
- package/dist/node/types/index.js +6 -0
- package/dist/node/vite-plugin/index.d.ts +13 -0
- package/dist/node/vite-plugin/index.js +11 -0
- package/package.json +94 -0
- package/src/client/App.tsx +101 -0
- package/src/client/Page.tsx +15 -0
- package/src/client/entry-server.tsx +79 -0
- package/src/client/index.html +18 -0
- package/src/client/main.tsx +11 -0
- package/src/theme/CodeBlock.tsx +103 -0
- package/src/theme/Content.tsx +32 -0
- package/src/theme/Footer.tsx +53 -0
- package/src/theme/Head.tsx +80 -0
- package/src/theme/HeadContext.tsx +32 -0
- package/src/theme/Header.tsx +177 -0
- package/src/theme/Layout.tsx +44 -0
- package/src/theme/MDXComponents.tsx +40 -0
- package/src/theme/NotFound.tsx +246 -0
- package/src/theme/Search.tsx +359 -0
- package/src/theme/Sidebar.tsx +325 -0
- package/src/theme/TableOfContents.tsx +153 -0
- package/src/theme/ThemeProvider.tsx +77 -0
- package/src/theme/components/Accordion.tsx +109 -0
- package/src/theme/components/Badge.tsx +72 -0
- package/src/theme/components/Breadcrumbs.tsx +88 -0
- package/src/theme/components/Callout.tsx +115 -0
- package/src/theme/components/Card.tsx +103 -0
- package/src/theme/components/CodeGroup.tsx +79 -0
- package/src/theme/components/Columns.tsx +42 -0
- package/src/theme/components/Frame.tsx +55 -0
- package/src/theme/components/Mermaid.tsx +99 -0
- package/src/theme/components/MermaidStatic.tsx +32 -0
- package/src/theme/components/OpenAPI.tsx +160 -0
- package/src/theme/components/OpenAPIPage.tsx +16 -0
- package/src/theme/components/Steps.tsx +76 -0
- package/src/theme/components/Tabs.tsx +75 -0
- package/src/theme/components/Tooltip.tsx +108 -0
- package/src/theme/components/index.ts +14 -0
- package/src/theme/styles/globals.css +363 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MarlinJai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Clearify
|
|
2
|
+
|
|
3
|
+
An open-source documentation site generator. Turn markdown into beautiful docs.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Zero config** — drop markdown files in `docs/public/` and go
|
|
8
|
+
- **MDX support** — use React components in your docs (Callout, Tabs, Steps, Cards, CodeGroup, Accordion, Badge, Tooltip, Columns, Frame)
|
|
9
|
+
- **Mermaid diagrams** — fenced `mermaid` code blocks render as SVG, with optional build-time pre-rendering via Puppeteer
|
|
10
|
+
- **Built-in search** — instant full-text search across all pages and API endpoints
|
|
11
|
+
- **Dark mode** — automatic light/dark theme switching
|
|
12
|
+
- **Syntax highlighting** — beautiful code blocks with Shiki (dual light/dark themes)
|
|
13
|
+
- **SSG & SEO** — pre-rendered HTML, Open Graph, Twitter Cards, JSON-LD, sitemap, robots.txt
|
|
14
|
+
- **OpenAPI / Scalar** — render API reference docs from an OpenAPI spec, with theme sync and dark mode
|
|
15
|
+
- **Multi-section support** — pill-based section switcher (e.g. public docs + internal docs)
|
|
16
|
+
- **Auto changelog** — drop a `CHANGELOG.md` in your project root, it appears as `/changelog`
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
Install Clearify as a dev dependency:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @marlinjai/clearify --save-dev
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Scaffold your project:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx clearify init
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Start the dev server:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npx clearify dev
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Your docs are live at `http://localhost:4747`.
|
|
39
|
+
|
|
40
|
+
## Configuration
|
|
41
|
+
|
|
42
|
+
Customize with `clearify.config.ts`:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { defineConfig } from '@marlinjai/clearify';
|
|
46
|
+
|
|
47
|
+
export default defineConfig({
|
|
48
|
+
name: 'My Project',
|
|
49
|
+
sections: [
|
|
50
|
+
{ label: 'Docs', docsDir: './docs/public' },
|
|
51
|
+
{ label: 'Internal', docsDir: './docs/internal', basePath: '/internal', draft: true },
|
|
52
|
+
],
|
|
53
|
+
theme: {
|
|
54
|
+
primaryColor: '#3B82F6',
|
|
55
|
+
mode: 'auto',
|
|
56
|
+
},
|
|
57
|
+
openapi: {
|
|
58
|
+
spec: './docs/openapi.json',
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## CLI Commands
|
|
64
|
+
|
|
65
|
+
| Command | Description |
|
|
66
|
+
|---------|-------------|
|
|
67
|
+
| `clearify dev` | Start Vite-powered dev server with HMR |
|
|
68
|
+
| `clearify build` | Build static documentation site |
|
|
69
|
+
| `clearify init` | Scaffold a docs folder (use `--no-internal` to skip internal section) |
|
|
70
|
+
| `clearify check` | Check for broken internal links |
|
|
71
|
+
| `clearify openapi:generate` | Generate OpenAPI spec from a NestJS app |
|
|
72
|
+
|
|
73
|
+
## Links
|
|
74
|
+
|
|
75
|
+
- [Documentation](https://github.com/marlinjai/clearify)
|
|
76
|
+
- [GitHub](https://github.com/marlinjai/clearify)
|
|
77
|
+
- [Changelog](./CHANGELOG.md)
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
[MIT](./LICENSE)
|
package/bin/clearify.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/core/search.ts
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import matter from "gray-matter";
|
|
4
|
+
function stripMarkdown(md) {
|
|
5
|
+
return md.replace(/^---[\s\S]*?---\n*/m, "").replace(/```[\s\S]*?```/g, "").replace(/`[^`]+`/g, "").replace(/#{1,6}\s/g, "").replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/!\[([^\]]*)\]\([^)]+\)/g, "$1").replace(/<[^>]+>/g, "").replace(/[*_]{1,3}([^*_]+)[*_]{1,3}/g, "$1").replace(/\s+/g, " ").trim();
|
|
6
|
+
}
|
|
7
|
+
function buildSearchIndex(docs, sectionId, sectionLabel) {
|
|
8
|
+
return docs.map((doc, i) => {
|
|
9
|
+
const raw = readFileSync(doc.filePath, "utf-8");
|
|
10
|
+
const { content } = matter(raw);
|
|
11
|
+
return {
|
|
12
|
+
id: i,
|
|
13
|
+
path: doc.routePath,
|
|
14
|
+
title: doc.frontmatter.title ?? "",
|
|
15
|
+
description: doc.frontmatter.description ?? "",
|
|
16
|
+
content: stripMarkdown(content),
|
|
17
|
+
...sectionId ? { sectionId } : {},
|
|
18
|
+
...sectionLabel ? { sectionLabel } : {}
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
buildSearchIndex
|
|
25
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/core/openapi-parser.ts
|
|
2
|
+
var HTTP_METHODS = ["get", "post", "put", "delete", "patch"];
|
|
3
|
+
function parseOpenAPISpec(spec) {
|
|
4
|
+
const tagMap = /* @__PURE__ */ new Map();
|
|
5
|
+
const tagDescriptions = /* @__PURE__ */ new Map();
|
|
6
|
+
if (Array.isArray(spec.tags)) {
|
|
7
|
+
for (const t of spec.tags) {
|
|
8
|
+
if (t.name && t.description) {
|
|
9
|
+
tagDescriptions.set(t.name, t.description);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const paths = spec.paths ?? {};
|
|
14
|
+
for (const [path, pathItem] of Object.entries(paths)) {
|
|
15
|
+
if (!pathItem || typeof pathItem !== "object") continue;
|
|
16
|
+
for (const method of HTTP_METHODS) {
|
|
17
|
+
const operation = pathItem[method];
|
|
18
|
+
if (!operation || typeof operation !== "object") continue;
|
|
19
|
+
const tags = Array.isArray(operation.tags) && operation.tags.length > 0 ? [operation.tags[0]] : ["Default"];
|
|
20
|
+
const op = {
|
|
21
|
+
method: method.toUpperCase(),
|
|
22
|
+
path,
|
|
23
|
+
summary: operation.summary ?? operation.description ?? `${method.toUpperCase()} ${path}`,
|
|
24
|
+
operationId: operation.operationId
|
|
25
|
+
};
|
|
26
|
+
for (const tag of tags) {
|
|
27
|
+
const existing = tagMap.get(tag);
|
|
28
|
+
if (existing) {
|
|
29
|
+
existing.push(op);
|
|
30
|
+
} else {
|
|
31
|
+
tagMap.set(tag, [op]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const groups = [];
|
|
37
|
+
for (const [tag, operations] of tagMap) {
|
|
38
|
+
operations.sort((a, b) => a.path.localeCompare(b.path));
|
|
39
|
+
groups.push({
|
|
40
|
+
tag,
|
|
41
|
+
description: tagDescriptions.get(tag),
|
|
42
|
+
operations
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
groups.sort((a, b) => {
|
|
46
|
+
if (a.tag === "Default") return 1;
|
|
47
|
+
if (b.tag === "Default") return -1;
|
|
48
|
+
return a.tag.localeCompare(b.tag);
|
|
49
|
+
});
|
|
50
|
+
return groups;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export {
|
|
54
|
+
parseOpenAPISpec
|
|
55
|
+
};
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clearPreRenderedMermaidSvgs,
|
|
3
|
+
remarkMermaidToComponent,
|
|
4
|
+
setPreRenderedMermaidSvgs
|
|
5
|
+
} from "./chunk-PRTER35L.js";
|
|
6
|
+
import {
|
|
7
|
+
mermaidContentHash
|
|
8
|
+
} from "./chunk-SCZZB7OE.js";
|
|
9
|
+
import {
|
|
10
|
+
clearifyPlugin
|
|
11
|
+
} from "./chunk-NXQNNLGC.js";
|
|
12
|
+
import {
|
|
13
|
+
loadUserConfig,
|
|
14
|
+
resolveConfig,
|
|
15
|
+
resolveSections
|
|
16
|
+
} from "./chunk-IBK35HZR.js";
|
|
17
|
+
import {
|
|
18
|
+
buildSectionData
|
|
19
|
+
} from "./chunk-L24ILRSX.js";
|
|
20
|
+
|
|
21
|
+
// src/node/build.ts
|
|
22
|
+
import { build as viteBuild } from "vite";
|
|
23
|
+
import react from "@vitejs/plugin-react";
|
|
24
|
+
import mdx from "@mdx-js/rollup";
|
|
25
|
+
import remarkGfm from "remark-gfm";
|
|
26
|
+
import remarkFrontmatter from "remark-frontmatter";
|
|
27
|
+
import remarkMdxFrontmatter from "remark-mdx-frontmatter";
|
|
28
|
+
import rehypeShiki from "@shikijs/rehype";
|
|
29
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
30
|
+
import { resolve } from "path";
|
|
31
|
+
import { writeFileSync, readFileSync, existsSync, mkdirSync, rmSync, copyFileSync } from "fs";
|
|
32
|
+
import { basename } from "path";
|
|
33
|
+
import { fileURLToPath } from "url";
|
|
34
|
+
function findPackageRoot() {
|
|
35
|
+
let dir = fileURLToPath(new URL(".", import.meta.url));
|
|
36
|
+
for (let i = 0; i < 10; i++) {
|
|
37
|
+
if (existsSync(resolve(dir, "package.json"))) return dir;
|
|
38
|
+
const parent = resolve(dir, "..");
|
|
39
|
+
if (parent === dir) break;
|
|
40
|
+
dir = parent;
|
|
41
|
+
}
|
|
42
|
+
return process.cwd();
|
|
43
|
+
}
|
|
44
|
+
function resolveClientPath(...segments) {
|
|
45
|
+
const packageRoot = findPackageRoot();
|
|
46
|
+
return resolve(packageRoot, "src", "client", ...segments);
|
|
47
|
+
}
|
|
48
|
+
function escapeHtml(str) {
|
|
49
|
+
return str.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
50
|
+
}
|
|
51
|
+
function generateSitemap(routes, siteUrl) {
|
|
52
|
+
const base = siteUrl?.replace(/\/$/, "") ?? "";
|
|
53
|
+
const urls = routes.map((r) => {
|
|
54
|
+
const loc = base ? `${base}${r.path === "/" ? "/" : r.path + "/"}` : r.path === "/" ? "/" : r.path + "/";
|
|
55
|
+
return ` <url><loc>${loc}</loc></url>`;
|
|
56
|
+
});
|
|
57
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
58
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
59
|
+
${urls.join("\n")}
|
|
60
|
+
</urlset>`;
|
|
61
|
+
}
|
|
62
|
+
function generateRobotsTxt(siteUrl) {
|
|
63
|
+
const lines = ["User-agent: *", "Allow: /"];
|
|
64
|
+
if (siteUrl) {
|
|
65
|
+
const base = siteUrl.replace(/\/$/, "");
|
|
66
|
+
lines.push(`Sitemap: ${base}/sitemap.xml`);
|
|
67
|
+
}
|
|
68
|
+
return lines.join("\n") + "\n";
|
|
69
|
+
}
|
|
70
|
+
function injectSSR(template, opts) {
|
|
71
|
+
const siteBase = opts.siteUrl?.replace(/\/$/, "") ?? "";
|
|
72
|
+
const canonical = siteBase ? `${siteBase}${opts.url}` : opts.url;
|
|
73
|
+
const escapedTitle = escapeHtml(opts.title);
|
|
74
|
+
const escapedDesc = escapeHtml(opts.description);
|
|
75
|
+
const escapedSiteName = escapeHtml(opts.siteName);
|
|
76
|
+
const headTags = [
|
|
77
|
+
`<title>${escapedTitle}</title>`,
|
|
78
|
+
`<meta name="description" content="${escapedDesc}" />`,
|
|
79
|
+
`<link rel="canonical" href="${canonical}" />`,
|
|
80
|
+
`<meta property="og:title" content="${escapedTitle}" />`,
|
|
81
|
+
`<meta property="og:description" content="${escapedDesc}" />`,
|
|
82
|
+
`<meta property="og:url" content="${canonical}" />`,
|
|
83
|
+
`<meta property="og:type" content="article" />`,
|
|
84
|
+
`<meta property="og:site_name" content="${escapedSiteName}" />`,
|
|
85
|
+
`<meta name="twitter:card" content="summary" />`,
|
|
86
|
+
`<meta name="twitter:title" content="${escapedTitle}" />`,
|
|
87
|
+
`<meta name="twitter:description" content="${escapedDesc}" />`,
|
|
88
|
+
`<script type="application/ld+json">${JSON.stringify({
|
|
89
|
+
"@context": "https://schema.org",
|
|
90
|
+
"@type": "Article",
|
|
91
|
+
headline: opts.title,
|
|
92
|
+
description: opts.description,
|
|
93
|
+
url: canonical
|
|
94
|
+
})}</script>`,
|
|
95
|
+
...opts.customCss ? [`<link rel="stylesheet" href="${escapeHtml(opts.customCss)}" />`] : [],
|
|
96
|
+
...opts.headTags ?? []
|
|
97
|
+
].join("\n ");
|
|
98
|
+
return template.replace("<title>Documentation</title>", "").replace("<!--clearify-head-->", headTags).replace("<!--clearify-outlet-->", opts.html).replace('<div id="root">', '<div id="root" data-clearify-ssr="true">');
|
|
99
|
+
}
|
|
100
|
+
function getSharedPlugins(userRoot, options) {
|
|
101
|
+
const plugins = [
|
|
102
|
+
tailwindcss(),
|
|
103
|
+
...clearifyPlugin({
|
|
104
|
+
root: userRoot,
|
|
105
|
+
mermaidSvgs: options?.mermaidSvgs,
|
|
106
|
+
mermaidStrategy: options?.mermaidStrategy
|
|
107
|
+
}),
|
|
108
|
+
{ enforce: "pre", ...mdx({
|
|
109
|
+
providerImportSource: "@mdx-js/react",
|
|
110
|
+
remarkPlugins: [remarkMermaidToComponent, remarkGfm, remarkFrontmatter, [remarkMdxFrontmatter, { name: "frontmatter" }]],
|
|
111
|
+
rehypePlugins: [
|
|
112
|
+
[rehypeShiki, {
|
|
113
|
+
themes: { light: "github-light", dark: "github-dark" },
|
|
114
|
+
defaultColor: false
|
|
115
|
+
}]
|
|
116
|
+
]
|
|
117
|
+
}) },
|
|
118
|
+
react({ include: /\.(jsx|tsx|md|mdx)$/ })
|
|
119
|
+
];
|
|
120
|
+
if (options?.mermaidStrategy === "build") {
|
|
121
|
+
plugins.push({
|
|
122
|
+
name: "clearify-stub-mermaid",
|
|
123
|
+
enforce: "pre",
|
|
124
|
+
resolveId(id) {
|
|
125
|
+
if (id === "mermaid") return "\0stub:mermaid";
|
|
126
|
+
},
|
|
127
|
+
load(id) {
|
|
128
|
+
if (id === "\0stub:mermaid") {
|
|
129
|
+
return 'export default { initialize() {}, render() { return { svg: "" }; } };';
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return plugins;
|
|
135
|
+
}
|
|
136
|
+
async function buildSite() {
|
|
137
|
+
const userRoot = process.cwd();
|
|
138
|
+
const root = resolveClientPath();
|
|
139
|
+
const userConfig = await loadUserConfig(userRoot);
|
|
140
|
+
const config = resolveConfig(userConfig);
|
|
141
|
+
const outDir = resolve(userRoot, config.outDir);
|
|
142
|
+
const ssrOutDir = resolve(outDir, ".ssr");
|
|
143
|
+
const allSections = resolveSections(config, userRoot);
|
|
144
|
+
const productionSections = allSections.filter((s) => !s.draft);
|
|
145
|
+
const changelogPath = resolve(userRoot, "CHANGELOG.md");
|
|
146
|
+
const sectionDataList = productionSections.map(
|
|
147
|
+
(section) => buildSectionData(section, changelogPath, config.navigation)
|
|
148
|
+
);
|
|
149
|
+
const allRoutes = sectionDataList.flatMap((sd) => sd.routes);
|
|
150
|
+
if (config.openapi?.spec && config.openapi.generatePages !== false) {
|
|
151
|
+
const basePath = config.openapi.basePath ?? "/api";
|
|
152
|
+
const specPath = resolve(userRoot, config.openapi.spec);
|
|
153
|
+
if (existsSync(specPath)) {
|
|
154
|
+
allRoutes.push({
|
|
155
|
+
path: `${basePath}/*`,
|
|
156
|
+
filePath: "",
|
|
157
|
+
componentPath: "@clearify/theme/components/OpenAPIPage",
|
|
158
|
+
frontmatter: { title: "API Reference", description: "API documentation" },
|
|
159
|
+
sectionId: "api"
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const mermaidStrategy = config.mermaid?.strategy ?? "client";
|
|
164
|
+
let mermaidSvgs;
|
|
165
|
+
if (mermaidStrategy === "build") {
|
|
166
|
+
console.log("Building documentation site...\n");
|
|
167
|
+
console.log(" Step 0: Pre-rendering Mermaid diagrams...");
|
|
168
|
+
const { MermaidRenderer } = await import("./core/mermaid-renderer.js");
|
|
169
|
+
const cacheDir = resolve(userRoot, "node_modules/.cache/clearify-mermaid");
|
|
170
|
+
const renderer = new MermaidRenderer({ cacheDir });
|
|
171
|
+
try {
|
|
172
|
+
await renderer.launch();
|
|
173
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
174
|
+
const mermaidRegex = /```mermaid\s*\n([\s\S]*?)```/g;
|
|
175
|
+
for (const route of allRoutes) {
|
|
176
|
+
if (!route.filePath.endsWith(".md") && !route.filePath.endsWith(".mdx")) continue;
|
|
177
|
+
if (!existsSync(route.filePath)) continue;
|
|
178
|
+
const content = readFileSync(route.filePath, "utf-8");
|
|
179
|
+
let match;
|
|
180
|
+
while ((match = mermaidRegex.exec(content)) !== null) {
|
|
181
|
+
const def = match[1].trim();
|
|
182
|
+
const hash = mermaidContentHash(def);
|
|
183
|
+
definitions.set(hash, def);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (definitions.size > 0) {
|
|
187
|
+
const rendered = await renderer.renderBatch(definitions);
|
|
188
|
+
mermaidSvgs = {};
|
|
189
|
+
const svgMap = /* @__PURE__ */ new Map();
|
|
190
|
+
for (const [hash, data] of rendered) {
|
|
191
|
+
mermaidSvgs[hash] = data;
|
|
192
|
+
svgMap.set(hash, data);
|
|
193
|
+
}
|
|
194
|
+
setPreRenderedMermaidSvgs(svgMap);
|
|
195
|
+
console.log(` Pre-rendered ${rendered.size} Mermaid diagrams`);
|
|
196
|
+
} else {
|
|
197
|
+
console.log(" No Mermaid diagrams found.");
|
|
198
|
+
}
|
|
199
|
+
} finally {
|
|
200
|
+
await renderer.close();
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
console.log("Building documentation site...\n");
|
|
204
|
+
}
|
|
205
|
+
console.log(" Step 1: Client build...");
|
|
206
|
+
const sharedPluginOptions = {
|
|
207
|
+
mermaidSvgs,
|
|
208
|
+
mermaidStrategy
|
|
209
|
+
};
|
|
210
|
+
const clientConfig = {
|
|
211
|
+
root,
|
|
212
|
+
plugins: getSharedPlugins(userRoot, sharedPluginOptions),
|
|
213
|
+
resolve: {
|
|
214
|
+
alias: { "@clearify": resolve(root, "..") }
|
|
215
|
+
},
|
|
216
|
+
build: {
|
|
217
|
+
outDir,
|
|
218
|
+
emptyOutDir: true
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
await viteBuild(clientConfig);
|
|
222
|
+
console.log(" Client build complete.");
|
|
223
|
+
console.log(" Step 2: SSR build...");
|
|
224
|
+
const ssrConfig = {
|
|
225
|
+
root,
|
|
226
|
+
plugins: getSharedPlugins(userRoot, sharedPluginOptions),
|
|
227
|
+
resolve: {
|
|
228
|
+
alias: { "@clearify": resolve(root, "..") }
|
|
229
|
+
},
|
|
230
|
+
build: {
|
|
231
|
+
outDir: ssrOutDir,
|
|
232
|
+
ssr: resolveClientPath("entry-server.tsx"),
|
|
233
|
+
emptyOutDir: true
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
await viteBuild(ssrConfig);
|
|
237
|
+
console.log(" SSR build complete.");
|
|
238
|
+
console.log(" Step 3: Pre-rendering pages...");
|
|
239
|
+
const template = readFileSync(resolve(outDir, "index.html"), "utf-8");
|
|
240
|
+
const ssrModule = await import(resolve(ssrOutDir, "entry-server.js"));
|
|
241
|
+
const { render } = ssrModule;
|
|
242
|
+
let resolvedCustomCssHref;
|
|
243
|
+
if (config.customCss) {
|
|
244
|
+
const cssSource = resolve(userRoot, config.customCss);
|
|
245
|
+
if (existsSync(cssSource)) {
|
|
246
|
+
const cssFilename = basename(cssSource);
|
|
247
|
+
copyFileSync(cssSource, resolve(outDir, cssFilename));
|
|
248
|
+
resolvedCustomCssHref = "/" + cssFilename;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
for (const route of allRoutes) {
|
|
252
|
+
const renderPath = route.path.endsWith("/*") ? route.path.slice(0, -2) : route.path;
|
|
253
|
+
try {
|
|
254
|
+
const { html, head } = await render(renderPath);
|
|
255
|
+
const page = injectSSR(template, {
|
|
256
|
+
html,
|
|
257
|
+
title: head.title,
|
|
258
|
+
description: head.description,
|
|
259
|
+
url: renderPath,
|
|
260
|
+
siteName: head.siteName,
|
|
261
|
+
siteUrl: config.siteUrl,
|
|
262
|
+
customCss: resolvedCustomCssHref,
|
|
263
|
+
headTags: config.headTags
|
|
264
|
+
});
|
|
265
|
+
if (renderPath === "/") {
|
|
266
|
+
writeFileSync(resolve(outDir, "index.html"), page);
|
|
267
|
+
} else {
|
|
268
|
+
const dir = resolve(outDir, renderPath.replace(/^\//, ""));
|
|
269
|
+
mkdirSync(dir, { recursive: true });
|
|
270
|
+
writeFileSync(resolve(dir, "index.html"), page);
|
|
271
|
+
}
|
|
272
|
+
console.log(` Pre-rendered: ${renderPath}`);
|
|
273
|
+
} catch (err) {
|
|
274
|
+
console.warn(` Failed to pre-render ${renderPath}:`, err instanceof Error ? err.message : err);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
writeFileSync(resolve(outDir, "robots.txt"), generateRobotsTxt(config.siteUrl));
|
|
278
|
+
console.log(" Generated robots.txt");
|
|
279
|
+
const sitemapSections = new Set(
|
|
280
|
+
productionSections.filter((s) => s.sitemap).map((s) => s.id)
|
|
281
|
+
);
|
|
282
|
+
if (config.openapi?.spec && config.openapi.generatePages !== false) {
|
|
283
|
+
sitemapSections.add("api");
|
|
284
|
+
}
|
|
285
|
+
const sitemapRoutes = allRoutes.filter((r) => !r.sectionId || sitemapSections.has(r.sectionId)).map((r) => ({ ...r, path: r.path.endsWith("/*") ? r.path.slice(0, -2) : r.path }));
|
|
286
|
+
const sitemap = generateSitemap(sitemapRoutes, config.siteUrl);
|
|
287
|
+
writeFileSync(resolve(outDir, "sitemap.xml"), sitemap);
|
|
288
|
+
console.log(" Generated sitemap.xml");
|
|
289
|
+
rmSync(ssrOutDir, { recursive: true, force: true });
|
|
290
|
+
console.log(" Cleaned up SSR build artifacts.");
|
|
291
|
+
if (mermaidStrategy === "build") {
|
|
292
|
+
clearPreRenderedMermaidSvgs();
|
|
293
|
+
}
|
|
294
|
+
console.log(`
|
|
295
|
+
Build complete! Output in ${config.outDir}/
|
|
296
|
+
`);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export {
|
|
300
|
+
buildSite
|
|
301
|
+
};
|