@nikala-ui/folio 0.15.0 → 0.16.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/dist/cli/commands/init.js +89 -54
- package/dist/components/ui/code-block-commands.d.ts +4 -0
- package/dist/components/ui/code-block-commands.js +58 -0
- package/dist/components/ui/code-block.d.ts +2 -1
- package/dist/components/ui/code-block.jsx +4 -127
- package/dist/components/ui/code-highlighter.d.ts +2 -0
- package/dist/components/ui/code-highlighter.js +76 -0
- package/dist/config.js +3 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/mdx/builtin-languages.d.ts +34 -0
- package/dist/mdx/builtin-languages.js +54 -0
- package/dist/mdx/custom-languages.d.ts +10 -0
- package/dist/mdx/custom-languages.js +52 -0
- package/dist/mdx/highlighter.d.ts +2 -1
- package/dist/mdx/highlighter.js +19 -52
- package/dist/search/provider.d.ts +9 -0
- package/dist/search/provider.js +4 -2
- package/dist/server/plugin/constants.d.ts +2 -0
- package/dist/server/plugin/constants.js +2 -0
- package/dist/server/plugin/index.js +2 -1
- package/dist/server/plugin/virtual-modules.js +41 -2
- package/dist/templates/env.d.ts +31 -0
- package/dist/templates/locales/en.json +77 -0
- package/dist/themes/default/components/docs-landing-body.d.ts +17 -0
- package/dist/themes/default/components/docs-landing-body.jsx +17 -0
- package/dist/themes/default/components/docs-page-body.d.ts +21 -0
- package/dist/themes/default/components/docs-page-body.jsx +36 -0
- package/dist/themes/default/components/page-actions.d.ts +15 -0
- package/dist/themes/default/components/page-actions.jsx +60 -0
- package/dist/themes/default/components/page-header.d.ts +7 -0
- package/dist/themes/default/components/page-header.jsx +3 -0
- package/dist/themes/default/components/sidebar-footer.d.ts +6 -0
- package/dist/themes/default/components/sidebar-footer.jsx +12 -0
- package/dist/themes/default/components/sidebar-header.d.ts +8 -0
- package/dist/themes/default/components/sidebar-header.jsx +17 -0
- package/dist/themes/default/components/sidebar-mobile-nav.d.ts +7 -0
- package/dist/themes/default/components/sidebar-mobile-nav.jsx +17 -0
- package/dist/themes/default/components/sidebar-promo.d.ts +8 -0
- package/dist/themes/default/components/sidebar-promo.jsx +20 -0
- package/dist/themes/default/hooks/use-page-copy.d.ts +6 -0
- package/dist/themes/default/hooks/use-page-copy.js +26 -0
- package/dist/themes/default/layout.jsx +23 -147
- package/dist/themes/default/lib/layout-visibility.d.ts +8 -0
- package/dist/themes/default/lib/layout-visibility.js +24 -0
- package/dist/themes/default/navigation/mobile-table-of-contents.jsx +2 -2
- package/dist/themes/default/sidebar.jsx +17 -47
- package/dist/types.d.ts +9 -0
- package/dist/vendor/docs-src/client/page-actions.ts +69 -0
- package/dist/vendor/docs-src/components/ui/code-block-commands.ts +65 -0
- package/dist/vendor/docs-src/components/ui/code-block.tsx +5 -132
- package/dist/vendor/docs-src/components/ui/code-highlighter.ts +76 -0
- package/dist/vendor/docs-src/navigation/index.ts +2 -0
- package/dist/vendor/docs-src/navigation/repository-links.ts +43 -0
- package/dist/vendor/docs-src/navigation/sidebar-state.ts +22 -0
- package/dist/vendor/docs-src/navigation/sidebar-tree.ts +15 -0
- package/dist/vendor/docs-src/search/provider.ts +83 -0
- package/dist/vendor/docs-src/themes/default/components/docs-landing-body.tsx +30 -0
- package/dist/vendor/docs-src/themes/default/components/docs-page-body.tsx +53 -0
- package/dist/vendor/docs-src/themes/default/components/page-actions.tsx +105 -0
- package/dist/vendor/docs-src/themes/default/components/page-header.tsx +31 -0
- package/dist/vendor/docs-src/themes/default/components/sidebar-footer.tsx +21 -0
- package/dist/vendor/docs-src/themes/default/components/sidebar-header.tsx +30 -0
- package/dist/vendor/docs-src/themes/default/components/sidebar-mobile-nav.tsx +33 -0
- package/dist/vendor/docs-src/themes/default/components/sidebar-promo.tsx +37 -0
- package/dist/vendor/docs-src/themes/default/content/breadcrumbs.tsx +43 -0
- package/dist/vendor/docs-src/themes/default/content/pager.tsx +19 -0
- package/dist/vendor/docs-src/themes/default/content/table-of-contents.tsx +32 -0
- package/dist/vendor/docs-src/themes/default/hooks/use-page-copy.ts +29 -0
- package/dist/vendor/docs-src/themes/default/icons.ts +16 -0
- package/dist/vendor/docs-src/themes/default/index.ts +46 -0
- package/dist/vendor/docs-src/themes/default/layout.tsx +176 -0
- package/dist/vendor/docs-src/themes/default/lib/layout-visibility.ts +39 -0
- package/dist/vendor/docs-src/themes/default/navbar.tsx +130 -0
- package/dist/vendor/docs-src/themes/default/navigation/mobile-table-of-contents.tsx +61 -0
- package/dist/vendor/docs-src/themes/default/navigation/sidebar-tree.tsx +202 -0
- package/dist/vendor/docs-src/themes/default/overlays/search-dialog.tsx +106 -0
- package/dist/vendor/docs-src/themes/default/sidebar.tsx +86 -0
- package/dist/vendor/docs-src/themes/index.ts +4 -0
- package/dist/vendor/docs-src/themes/types.ts +87 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
function textContent(node: Node): string {
|
|
2
|
+
return node.textContent?.replace(/\s+/g, " ").trim() || "";
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function renderInline(node: Node): string {
|
|
6
|
+
if (node.nodeType === Node.TEXT_NODE) return node.textContent || "";
|
|
7
|
+
if (!(node instanceof HTMLElement)) return "";
|
|
8
|
+
|
|
9
|
+
const content = Array.from(node.childNodes).map(renderInline).join("");
|
|
10
|
+
if (node.tagName === "A") {
|
|
11
|
+
const href = node.getAttribute("href");
|
|
12
|
+
return href ? `[${content.trim()}](${href})` : content;
|
|
13
|
+
}
|
|
14
|
+
if (node.tagName === "CODE" && node.parentElement?.tagName !== "PRE") return `\`${content.trim()}\``;
|
|
15
|
+
return content;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function renderBlock(node: Node): string {
|
|
19
|
+
if (node.nodeType === Node.TEXT_NODE) return textContent(node);
|
|
20
|
+
if (!(node instanceof HTMLElement)) return "";
|
|
21
|
+
|
|
22
|
+
if (/^H[1-6]$/.test(node.tagName)) {
|
|
23
|
+
const level = Number(node.tagName.slice(1));
|
|
24
|
+
return `${"#".repeat(level)} ${renderInline(node).trim()}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (node.tagName === "PRE") return `\`\`\`\n${node.textContent?.trim() || ""}\n\`\`\``;
|
|
28
|
+
if (node.tagName === "LI") return `- ${renderInline(node).trim()}`;
|
|
29
|
+
|
|
30
|
+
const content = Array.from(node.childNodes).map(renderBlock).filter(Boolean).join("\n\n");
|
|
31
|
+
return content || renderInline(node).trim();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function pageToMarkdown(article: HTMLElement): string {
|
|
35
|
+
return Array.from(article.children)
|
|
36
|
+
.map(renderBlock)
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
.join("\n\n")
|
|
39
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
40
|
+
.trim();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function sourceToMarkdown(source: string): string {
|
|
44
|
+
return source
|
|
45
|
+
.replace(/^---\s*\n[\s\S]*?\n---\s*\n?/, "")
|
|
46
|
+
.trim();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function pageToText(article: HTMLElement): string {
|
|
50
|
+
return article.innerText.trim();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function resolvePageActionUrl(
|
|
54
|
+
template: string,
|
|
55
|
+
values: { url: string; content: string; title?: string; prompt?: string },
|
|
56
|
+
): string {
|
|
57
|
+
const prompt = values.prompt
|
|
58
|
+
? values.prompt
|
|
59
|
+
.replaceAll("{url}", values.url)
|
|
60
|
+
.replaceAll("{content}", values.content)
|
|
61
|
+
.replaceAll("{title}", values.title || "")
|
|
62
|
+
: "";
|
|
63
|
+
|
|
64
|
+
return template
|
|
65
|
+
.replaceAll("{url}", encodeURIComponent(values.url))
|
|
66
|
+
.replaceAll("{content}", encodeURIComponent(values.content))
|
|
67
|
+
.replaceAll("{title}", encodeURIComponent(values.title || ""))
|
|
68
|
+
.replaceAll("{prompt}", encodeURIComponent(prompt));
|
|
69
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Pure helpers that format and highlight CLI commands for CodeBlock's package manager runner.
|
|
2
|
+
|
|
3
|
+
export type CodeBlockPackageManager = "bunx" | "npx" | "pnpm" | "yarn";
|
|
4
|
+
|
|
5
|
+
export function highlightCliCommand(code: string): string {
|
|
6
|
+
const trimmed = code.trim();
|
|
7
|
+
const parts = trimmed.split(/\s+/);
|
|
8
|
+
if (parts.length === 0) return code;
|
|
9
|
+
|
|
10
|
+
const isRunner = ["bunx", "npx", "pnpm", "yarn", "bun", "npm", "cargo", "deno"].includes(parts[0]);
|
|
11
|
+
if (!isRunner) return `<span class="text-foreground">${escapeHtml(trimmed)}</span>`;
|
|
12
|
+
|
|
13
|
+
return parts
|
|
14
|
+
.map((part, index) => {
|
|
15
|
+
if (index === 0) {
|
|
16
|
+
return `<span class="text-amber-500 dark:text-amber-400 font-bold">${escapeHtml(part)}</span>`;
|
|
17
|
+
}
|
|
18
|
+
if (part.startsWith("-")) {
|
|
19
|
+
return `<span class="text-purple-400 dark:text-purple-300">${escapeHtml(part)}</span>`;
|
|
20
|
+
}
|
|
21
|
+
if (part.startsWith("@")) {
|
|
22
|
+
return `<span class="text-emerald-400 dark:text-emerald-300 font-medium">${escapeHtml(part)}</span>`;
|
|
23
|
+
}
|
|
24
|
+
if (index === 1 && ["add", "install", "init", "create", "run"].includes(part)) {
|
|
25
|
+
return `<span class="text-sky-500 dark:text-sky-400 font-medium">${escapeHtml(part)}</span>`;
|
|
26
|
+
}
|
|
27
|
+
return `<span class="text-foreground/90">${escapeHtml(part)}</span>`;
|
|
28
|
+
})
|
|
29
|
+
.join(" ");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function transformCommandForPm(cmd: string, pm: CodeBlockPackageManager): string {
|
|
33
|
+
const trimmed = cmd.trim();
|
|
34
|
+
const runners = ["bunx", "npx", "pnpm dlx", "pnpm", "yarn dlx", "yarn", "bun", "npm"];
|
|
35
|
+
|
|
36
|
+
let base = trimmed;
|
|
37
|
+
for (const r of runners) {
|
|
38
|
+
if (trimmed.startsWith(r)) {
|
|
39
|
+
base = trimmed.slice(r.length).trim();
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
switch (pm) {
|
|
45
|
+
case "bunx":
|
|
46
|
+
return `bunx ${base}`;
|
|
47
|
+
case "npx":
|
|
48
|
+
return `npx ${base}`;
|
|
49
|
+
case "pnpm":
|
|
50
|
+
return `pnpm dlx ${base}`;
|
|
51
|
+
case "yarn":
|
|
52
|
+
return `yarn dlx ${base}`;
|
|
53
|
+
default:
|
|
54
|
+
return `${pm} ${base}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function escapeHtml(str: string): string {
|
|
59
|
+
return str
|
|
60
|
+
.replace(/&/g, "&")
|
|
61
|
+
.replace(/</g, "<")
|
|
62
|
+
.replace(/>/g, ">")
|
|
63
|
+
.replace(/"/g, """)
|
|
64
|
+
.replace(/'/g, "'");
|
|
65
|
+
}
|
|
@@ -14,10 +14,12 @@ import { Badge } from "@/components/ui/badge";
|
|
|
14
14
|
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
|
15
15
|
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
|
|
16
16
|
import { createClipboard } from "@/hooks/create-clipboard";
|
|
17
|
+
import { highlightOnClient } from "./code-highlighter";
|
|
18
|
+
import { escapeHtml, highlightCliCommand, transformCommandForPm, type CodeBlockPackageManager } from "./code-block-commands";
|
|
17
19
|
import { useSiteLocale } from "../../plugins/i18n/runtime.jsx";
|
|
18
20
|
import { cn } from "@/lib/cn";
|
|
19
21
|
|
|
20
|
-
export type CodeBlockPackageManager
|
|
22
|
+
export type { CodeBlockPackageManager };
|
|
21
23
|
|
|
22
24
|
export interface CodeBlockProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
23
25
|
/** The raw source code text to display and copy */
|
|
@@ -39,118 +41,6 @@ export interface CodeBlockProps extends JSX.HTMLAttributes<HTMLDivElement> {
|
|
|
39
41
|
class?: string;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
let shikiHighlighterPromise: Promise<any> | null = null;
|
|
43
|
-
|
|
44
|
-
async function getShikiHighlighter() {
|
|
45
|
-
if (typeof window === "undefined") return null;
|
|
46
|
-
if (!shikiHighlighterPromise) {
|
|
47
|
-
try {
|
|
48
|
-
const [{ createBundledHighlighter }, { createJavaScriptRegexEngine }] = await Promise.all([
|
|
49
|
-
import("shiki/core"),
|
|
50
|
-
import("shiki/engine/javascript"),
|
|
51
|
-
]);
|
|
52
|
-
const createHighlighter = createBundledHighlighter({
|
|
53
|
-
langs: {
|
|
54
|
-
typescript: () => import("@shikijs/langs/typescript"),
|
|
55
|
-
javascript: () => import("@shikijs/langs/javascript"),
|
|
56
|
-
tsx: () => import("@shikijs/langs/tsx"),
|
|
57
|
-
jsx: () => import("@shikijs/langs/jsx"),
|
|
58
|
-
bash: () => import("@shikijs/langs/shellscript"),
|
|
59
|
-
json: () => import("@shikijs/langs/json"),
|
|
60
|
-
css: () => import("@shikijs/langs/css"),
|
|
61
|
-
html: () => import("@shikijs/langs/html"),
|
|
62
|
-
rust: () => import("@shikijs/langs/rust"),
|
|
63
|
-
},
|
|
64
|
-
themes: {
|
|
65
|
-
"github-dark": () => import("@shikijs/themes/github-dark"),
|
|
66
|
-
"github-light": () => import("@shikijs/themes/github-light"),
|
|
67
|
-
},
|
|
68
|
-
engine: () => createJavaScriptRegexEngine(),
|
|
69
|
-
});
|
|
70
|
-
shikiHighlighterPromise = createHighlighter({
|
|
71
|
-
themes: ["github-dark", "github-light"],
|
|
72
|
-
langs: [
|
|
73
|
-
"typescript",
|
|
74
|
-
"javascript",
|
|
75
|
-
"tsx",
|
|
76
|
-
"jsx",
|
|
77
|
-
"bash",
|
|
78
|
-
"json",
|
|
79
|
-
"css",
|
|
80
|
-
"html",
|
|
81
|
-
"rust",
|
|
82
|
-
],
|
|
83
|
-
});
|
|
84
|
-
} catch (e) {
|
|
85
|
-
console.warn("Failed to load Shiki highlighter", e);
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return shikiHighlighterPromise;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function highlightCliCommand(code: string): string {
|
|
93
|
-
const trimmed = code.trim();
|
|
94
|
-
const parts = trimmed.split(/\s+/);
|
|
95
|
-
if (parts.length === 0) return code;
|
|
96
|
-
|
|
97
|
-
const isRunner = ["bunx", "npx", "pnpm", "yarn", "bun", "npm", "cargo", "deno"].includes(parts[0]);
|
|
98
|
-
if (!isRunner) return `<span class="text-foreground">${escapeHtml(trimmed)}</span>`;
|
|
99
|
-
|
|
100
|
-
return parts
|
|
101
|
-
.map((part, index) => {
|
|
102
|
-
if (index === 0) {
|
|
103
|
-
return `<span class="text-amber-500 dark:text-amber-400 font-bold">${escapeHtml(part)}</span>`;
|
|
104
|
-
}
|
|
105
|
-
if (part.startsWith("-")) {
|
|
106
|
-
return `<span class="text-purple-400 dark:text-purple-300">${escapeHtml(part)}</span>`;
|
|
107
|
-
}
|
|
108
|
-
if (part.startsWith("@")) {
|
|
109
|
-
return `<span class="text-emerald-400 dark:text-emerald-300 font-medium">${escapeHtml(part)}</span>`;
|
|
110
|
-
}
|
|
111
|
-
if (index === 1 && ["add", "install", "init", "create", "run"].includes(part)) {
|
|
112
|
-
return `<span class="text-sky-500 dark:text-sky-400 font-medium">${escapeHtml(part)}</span>`;
|
|
113
|
-
}
|
|
114
|
-
return `<span class="text-foreground/90">${escapeHtml(part)}</span>`;
|
|
115
|
-
})
|
|
116
|
-
.join(" ");
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function transformCommandForPm(cmd: string, pm: CodeBlockPackageManager): string {
|
|
120
|
-
const trimmed = cmd.trim();
|
|
121
|
-
const runners = ["bunx", "npx", "pnpm dlx", "pnpm", "yarn dlx", "yarn", "bun", "npm"];
|
|
122
|
-
|
|
123
|
-
let base = trimmed;
|
|
124
|
-
for (const r of runners) {
|
|
125
|
-
if (trimmed.startsWith(r)) {
|
|
126
|
-
base = trimmed.slice(r.length).trim();
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
switch (pm) {
|
|
132
|
-
case "bunx":
|
|
133
|
-
return `bunx ${base}`;
|
|
134
|
-
case "npx":
|
|
135
|
-
return `npx ${base}`;
|
|
136
|
-
case "pnpm":
|
|
137
|
-
return `pnpm dlx ${base}`;
|
|
138
|
-
case "yarn":
|
|
139
|
-
return `yarn dlx ${base}`;
|
|
140
|
-
default:
|
|
141
|
-
return `${pm} ${base}`;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function escapeHtml(str: string): string {
|
|
146
|
-
return str
|
|
147
|
-
.replace(/&/g, "&")
|
|
148
|
-
.replace(/</g, "<")
|
|
149
|
-
.replace(/>/g, ">")
|
|
150
|
-
.replace(/"/g, """)
|
|
151
|
-
.replace(/'/g, "'");
|
|
152
|
-
}
|
|
153
|
-
|
|
154
44
|
export const CodeBlock: ParentComponent<CodeBlockProps> = (props) => {
|
|
155
45
|
const siteLocale = useSiteLocale();
|
|
156
46
|
const [local, rest] = splitProps(props, [
|
|
@@ -203,25 +93,8 @@ export const CodeBlock: ParentComponent<CodeBlockProps> = (props) => {
|
|
|
203
93
|
return;
|
|
204
94
|
}
|
|
205
95
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (highlighter) {
|
|
209
|
-
try {
|
|
210
|
-
const html = highlighter.codeToHtml(codeStr, {
|
|
211
|
-
lang: lang === "js" ? "javascript" : lang === "ts" ? "typescript" : lang,
|
|
212
|
-
themes: {
|
|
213
|
-
light: "github-light",
|
|
214
|
-
dark: "github-dark",
|
|
215
|
-
},
|
|
216
|
-
});
|
|
217
|
-
setHighlightedHtml(html);
|
|
218
|
-
return;
|
|
219
|
-
} catch (err) {
|
|
220
|
-
console.warn(`Shiki failed for language: ${lang}`, err);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
// Fallback
|
|
224
|
-
setHighlightedHtml(`<pre class="text-foreground/90"><code>${escapeHtml(codeStr)}</code></pre>`);
|
|
96
|
+
highlightOnClient(codeStr, lang).then((html) => {
|
|
97
|
+
setHighlightedHtml(html ?? `<pre class="text-foreground/90"><code>${escapeHtml(codeStr)}</code></pre>`);
|
|
225
98
|
});
|
|
226
99
|
});
|
|
227
100
|
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Browser-side Shiki highlighting for CodeBlock usages without server-rendered children.
|
|
2
|
+
let highlighterPromise: Promise<any> | null = null;
|
|
3
|
+
|
|
4
|
+
async function getHighlighter() {
|
|
5
|
+
if (typeof window === "undefined") return null;
|
|
6
|
+
if (!highlighterPromise) {
|
|
7
|
+
try {
|
|
8
|
+
const [{ createBundledHighlighter }, { createJavaScriptRegexEngine }] = await Promise.all([
|
|
9
|
+
import("shiki/core"),
|
|
10
|
+
import("shiki/engine/javascript"),
|
|
11
|
+
]);
|
|
12
|
+
const createHighlighter = createBundledHighlighter({
|
|
13
|
+
langs: {
|
|
14
|
+
typescript: () => import("@shikijs/langs/typescript"),
|
|
15
|
+
javascript: () => import("@shikijs/langs/javascript"),
|
|
16
|
+
tsx: () => import("@shikijs/langs/tsx"),
|
|
17
|
+
jsx: () => import("@shikijs/langs/jsx"),
|
|
18
|
+
bash: () => import("@shikijs/langs/shellscript"),
|
|
19
|
+
json: () => import("@shikijs/langs/json"),
|
|
20
|
+
css: () => import("@shikijs/langs/css"),
|
|
21
|
+
html: () => import("@shikijs/langs/html"),
|
|
22
|
+
rust: () => import("@shikijs/langs/rust"),
|
|
23
|
+
},
|
|
24
|
+
themes: {
|
|
25
|
+
"github-dark": () => import("@shikijs/themes/github-dark"),
|
|
26
|
+
"github-light": () => import("@shikijs/themes/github-light"),
|
|
27
|
+
},
|
|
28
|
+
engine: () => createJavaScriptRegexEngine(),
|
|
29
|
+
});
|
|
30
|
+
highlighterPromise = createHighlighter({
|
|
31
|
+
themes: ["github-dark", "github-light"],
|
|
32
|
+
langs: ["typescript", "javascript", "tsx", "jsx", "bash", "json", "css", "html", "rust"],
|
|
33
|
+
});
|
|
34
|
+
} catch (e) {
|
|
35
|
+
console.warn("Failed to load Shiki highlighter", e);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return highlighterPromise;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Resolve a language from the site's `shiki.customLangs`. The grammar module is
|
|
44
|
+
* a separate lazy chunk, fetched only for languages the highlighter lacks.
|
|
45
|
+
*/
|
|
46
|
+
async function loadCustomLanguage(highlighter: any, lang: string): Promise<string | null> {
|
|
47
|
+
try {
|
|
48
|
+
const { default: languages } = await import("virtual:folio-highlight-languages");
|
|
49
|
+
const match = languages.find((entry) =>
|
|
50
|
+
[entry.name, ...(entry.aliases ?? [])].some((id) => id.toLowerCase() === lang),
|
|
51
|
+
);
|
|
52
|
+
if (!match) return null;
|
|
53
|
+
await highlighter.loadLanguage(match);
|
|
54
|
+
return match.name;
|
|
55
|
+
} catch (err) {
|
|
56
|
+
console.warn(`Failed to load custom Shiki language: ${lang}`, err);
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Highlight code in the browser, or return null when the caller should fall back to plain text. */
|
|
62
|
+
export async function highlightOnClient(code: string, rawLang: string): Promise<string | null> {
|
|
63
|
+
const highlighter = await getHighlighter();
|
|
64
|
+
if (!highlighter) return null;
|
|
65
|
+
|
|
66
|
+
const requested = rawLang === "js" ? "javascript" : rawLang === "ts" ? "typescript" : rawLang;
|
|
67
|
+
const lang = highlighter.getLoadedLanguages().includes(requested)
|
|
68
|
+
? requested
|
|
69
|
+
: (await loadCustomLanguage(highlighter, requested.toLowerCase())) ?? requested;
|
|
70
|
+
try {
|
|
71
|
+
return highlighter.codeToHtml(code, { lang, themes: { light: "github-light", dark: "github-dark" } });
|
|
72
|
+
} catch (err) {
|
|
73
|
+
console.warn(`Shiki failed for language: ${rawLang}`, err);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { DocsConfig } from "../types.js";
|
|
2
|
+
|
|
3
|
+
function normalizeRepositoryPath(...parts: string[]): string | undefined {
|
|
4
|
+
const segments = parts
|
|
5
|
+
.flatMap((part) => part.replace(/\\/g, "/").split("/"))
|
|
6
|
+
.filter((segment) => segment && segment !== ".");
|
|
7
|
+
|
|
8
|
+
if (segments.some((segment) => segment === "..")) return undefined;
|
|
9
|
+
return segments.map((segment) => encodeURIComponent(segment)).join("/");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function repositoryBaseUrl(url: string): string | undefined {
|
|
13
|
+
try {
|
|
14
|
+
const parsed = new URL(url);
|
|
15
|
+
if (!parsed.protocol.startsWith("http")) return undefined;
|
|
16
|
+
return parsed.toString().replace(/\/$/, "").replace(/\.git$/, "");
|
|
17
|
+
} catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getRepositorySourceUrl(
|
|
23
|
+
repository: NonNullable<DocsConfig["repository"]>,
|
|
24
|
+
sourcePath: string,
|
|
25
|
+
contentDir = "docs",
|
|
26
|
+
): string | undefined {
|
|
27
|
+
const baseUrl = repositoryBaseUrl(repository.url);
|
|
28
|
+
const filePath = normalizeRepositoryPath(repository.rootDir || "", contentDir, sourcePath);
|
|
29
|
+
if (!baseUrl || !filePath) return undefined;
|
|
30
|
+
|
|
31
|
+
const branch = encodeURIComponent(repository.branch || "main");
|
|
32
|
+
const hostname = new URL(baseUrl).hostname.toLowerCase();
|
|
33
|
+
|
|
34
|
+
if (hostname === "gitlab.com" || hostname.endsWith(".gitlab.com")) {
|
|
35
|
+
return `${baseUrl}/-/blob/${branch}/${filePath}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (hostname === "bitbucket.org" || hostname.endsWith(".bitbucket.org")) {
|
|
39
|
+
return `${baseUrl}/src/${branch}/${filePath}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return `${baseUrl}/blob/${branch}/${filePath}`;
|
|
43
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SidebarItem } from "../types.js";
|
|
2
|
+
|
|
3
|
+
export function isSidebarItemActive(item: SidebarItem, currentUrl?: string): boolean {
|
|
4
|
+
return Boolean(item.href && currentUrl && item.href === currentUrl);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function containsActiveSidebarItem(item: SidebarItem, currentUrl?: string): boolean {
|
|
8
|
+
return isSidebarItemActive(item, currentUrl)
|
|
9
|
+
|| Boolean(item.items?.some((child) => containsActiveSidebarItem(child, currentUrl)));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function isSidebarItemNew(item: SidebarItem): boolean {
|
|
13
|
+
if (!item.addedAt) return false;
|
|
14
|
+
const timestamp = new Date(item.addedAt).getTime();
|
|
15
|
+
if (!Number.isFinite(timestamp)) return false;
|
|
16
|
+
const ageInDays = (Date.now() - timestamp) / (1000 * 60 * 60 * 24);
|
|
17
|
+
return ageInDays >= 0 && ageInDays <= 14;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function containsNewSidebarItem(item: SidebarItem): boolean {
|
|
21
|
+
return isSidebarItemNew(item) || Boolean(item.items?.some(containsNewSidebarItem));
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SidebarItem } from "../types.js";
|
|
2
|
+
|
|
3
|
+
export interface FlatSidebarItem {
|
|
4
|
+
title: string;
|
|
5
|
+
href: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function flattenSidebarItems(items: SidebarItem[]): FlatSidebarItem[] {
|
|
9
|
+
const flattened: FlatSidebarItem[] = [];
|
|
10
|
+
for (const item of items) {
|
|
11
|
+
if (item.href) flattened.push({ title: item.title, href: item.href });
|
|
12
|
+
if (item.items) flattened.push(...flattenSidebarItems(item.items));
|
|
13
|
+
}
|
|
14
|
+
return flattened;
|
|
15
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { DocsConfig, PageData } from "../types.js";
|
|
2
|
+
|
|
3
|
+
export const LOCAL_SEARCH_PROVIDER = "local";
|
|
4
|
+
|
|
5
|
+
export interface SearchContext {
|
|
6
|
+
query: string;
|
|
7
|
+
pages: PageData[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SearchAdapterRuntime {
|
|
11
|
+
/** Browser module that exports the adapter factory. */
|
|
12
|
+
module: string;
|
|
13
|
+
/** Named export containing a factory that receives the optional adapter options. */
|
|
14
|
+
exportName: string;
|
|
15
|
+
/** JSON-serializable options passed to the browser adapter factory. */
|
|
16
|
+
options?: unknown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface SearchAdapter {
|
|
20
|
+
name: string;
|
|
21
|
+
search: (context: SearchContext) => PageData[] | Promise<PageData[]>;
|
|
22
|
+
runtime?: SearchAdapterRuntime;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type ConfiguredSearchProvider = NonNullable<DocsConfig["search"]>["provider"];
|
|
26
|
+
|
|
27
|
+
export interface ResolvedSearchProvider {
|
|
28
|
+
requested: string;
|
|
29
|
+
active: string;
|
|
30
|
+
fallback: boolean;
|
|
31
|
+
implementation: SearchAdapter;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const localSearchAdapter: SearchAdapter = {
|
|
35
|
+
name: LOCAL_SEARCH_PROVIDER,
|
|
36
|
+
search({ query, pages }) {
|
|
37
|
+
const normalizedQuery = query.trim().toLowerCase();
|
|
38
|
+
if (!normalizedQuery) return pages;
|
|
39
|
+
|
|
40
|
+
return pages.filter((page) =>
|
|
41
|
+
[page.title, page.url, page.description]
|
|
42
|
+
.filter(Boolean)
|
|
43
|
+
.some((value) => value!.toLowerCase().includes(normalizedQuery))
|
|
44
|
+
);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Resolve the configured search provider to an implementation available in
|
|
50
|
+
* the default theme. External indexes can be added later without changing
|
|
51
|
+
* the configuration contract or leaving the search dialog non-functional.
|
|
52
|
+
*/
|
|
53
|
+
export function resolveSearchProvider(search?: DocsConfig["search"]): ResolvedSearchProvider {
|
|
54
|
+
const configuredProvider = search?.provider;
|
|
55
|
+
|
|
56
|
+
if (configuredProvider && typeof configuredProvider !== "string" && typeof configuredProvider.search === "function") {
|
|
57
|
+
return {
|
|
58
|
+
requested: configuredProvider.name,
|
|
59
|
+
active: configuredProvider.name,
|
|
60
|
+
fallback: false,
|
|
61
|
+
implementation: configuredProvider,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const requested = typeof configuredProvider === "string"
|
|
66
|
+
? configuredProvider.trim() || LOCAL_SEARCH_PROVIDER
|
|
67
|
+
: configuredProvider?.name || LOCAL_SEARCH_PROVIDER;
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
requested,
|
|
71
|
+
active: LOCAL_SEARCH_PROVIDER,
|
|
72
|
+
fallback: requested !== LOCAL_SEARCH_PROVIDER,
|
|
73
|
+
implementation: localSearchAdapter,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function searchPages(
|
|
78
|
+
provider: ResolvedSearchProvider,
|
|
79
|
+
query: string,
|
|
80
|
+
pages: PageData[],
|
|
81
|
+
): PageData[] | Promise<PageData[]> {
|
|
82
|
+
return provider.implementation.search({ query, pages });
|
|
83
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Show, type Component, type JSX } from "solid-js";
|
|
2
|
+
import { Container } from "@/components/ui/container";
|
|
3
|
+
import { DocsBreadcrumbs } from "../content/breadcrumbs.jsx";
|
|
4
|
+
import { DocsPager } from "../content/pager.jsx";
|
|
5
|
+
import type { BreadcrumbItemData } from "../../types.js";
|
|
6
|
+
|
|
7
|
+
export interface DocsLandingBodyProps {
|
|
8
|
+
breadcrumbs?: BreadcrumbItemData[];
|
|
9
|
+
showBreadcrumbs: boolean;
|
|
10
|
+
showPager: boolean;
|
|
11
|
+
prev?: { title: string; href: string };
|
|
12
|
+
next?: { title: string; href: string };
|
|
13
|
+
children?: JSX.Element;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const DocsLandingBody: Component<DocsLandingBodyProps> = (props) => (
|
|
17
|
+
<Container as="main" size="2xl" class="min-w-0 max-w-full flex-1 py-8 sm:py-12 lg:py-16">
|
|
18
|
+
<Container as="article" size="xl" class="mx-auto min-w-0 px-0 sm:px-4">
|
|
19
|
+
<Show when={props.showBreadcrumbs && props.breadcrumbs && props.breadcrumbs.length > 0}>
|
|
20
|
+
<DocsBreadcrumbs items={props.breadcrumbs!} class="mb-6" />
|
|
21
|
+
</Show>
|
|
22
|
+
<Container as="div" size="full" class="prose prose-zinc dark:prose-invert max-w-none px-0" data-docs-page-content>
|
|
23
|
+
{props.children}
|
|
24
|
+
</Container>
|
|
25
|
+
<Show when={props.showPager && (props.prev || props.next)}>
|
|
26
|
+
<DocsPager prev={props.prev} next={props.next} />
|
|
27
|
+
</Show>
|
|
28
|
+
</Container>
|
|
29
|
+
</Container>
|
|
30
|
+
);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Show, type Component, type JSX } from "solid-js";
|
|
2
|
+
import { Container } from "@/components/ui/container";
|
|
3
|
+
import { DocsBreadcrumbs } from "../content/breadcrumbs.jsx";
|
|
4
|
+
import { DocsPager } from "../content/pager.jsx";
|
|
5
|
+
import { DocsTableOfContents } from "../content/table-of-contents.jsx";
|
|
6
|
+
import { DocsMobileTableOfContents } from "../navigation/mobile-table-of-contents.jsx";
|
|
7
|
+
import { SidebarPromo } from "./sidebar-promo.jsx";
|
|
8
|
+
import type { BreadcrumbItemData } from "../../types.js";
|
|
9
|
+
import type { PageData, TocItem } from "../../../types.js";
|
|
10
|
+
|
|
11
|
+
export interface DocsPageBodyProps {
|
|
12
|
+
breadcrumbs?: BreadcrumbItemData[];
|
|
13
|
+
currentPage?: PageData;
|
|
14
|
+
toc?: TocItem[];
|
|
15
|
+
prev?: { title: string; href: string };
|
|
16
|
+
next?: { title: string; href: string };
|
|
17
|
+
showToc: boolean;
|
|
18
|
+
pageActions: JSX.Element;
|
|
19
|
+
sidebarPromo?: NonNullable<NonNullable<import("../../../types.js").DocsNavigationConfig["sidebar"]>["promo"]>;
|
|
20
|
+
children?: JSX.Element;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const DocsPageBody: Component<DocsPageBodyProps> = (props) => (
|
|
24
|
+
<Container as="main" size="2xl" class="min-w-0 w-full max-w-[96rem] flex-1 grid grid-cols-1 xl:grid-cols-[minmax(0,1fr)_16rem] items-start gap-4 sm:gap-8 py-6 sm:py-8">
|
|
25
|
+
<Container as="article" size="full" class="min-w-0 max-w-none mx-0 px-0 sm:px-4 w-full">
|
|
26
|
+
<Show when={props.breadcrumbs && props.breadcrumbs.length > 0}>
|
|
27
|
+
<DocsBreadcrumbs items={props.breadcrumbs!} class="mb-6" />
|
|
28
|
+
</Show>
|
|
29
|
+
<Show when={props.currentPage?.title}>
|
|
30
|
+
{props.pageActions}
|
|
31
|
+
</Show>
|
|
32
|
+
<Show when={props.showToc}>
|
|
33
|
+
<DocsMobileTableOfContents items={props.toc!} class="mb-6" />
|
|
34
|
+
</Show>
|
|
35
|
+
<Container as="div" size="full" class="prose prose-zinc dark:prose-invert max-w-none px-0 sm:px-0 lg:px-0" data-docs-page-content>
|
|
36
|
+
{props.children}
|
|
37
|
+
</Container>
|
|
38
|
+
<Show when={props.prev || props.next}>
|
|
39
|
+
<DocsPager prev={props.prev} next={props.next} />
|
|
40
|
+
</Show>
|
|
41
|
+
</Container>
|
|
42
|
+
<Show when={props.showToc && props.currentPage?.url} keyed>
|
|
43
|
+
<Container as="aside" size="sm" class="hidden xl:block w-64 shrink-0 self-start px-0 sticky top-14 z-10 h-fit max-h-[calc(100vh-3.5rem)] overflow-y-auto bg-background">
|
|
44
|
+
<div class="flex flex-col gap-5">
|
|
45
|
+
<DocsTableOfContents items={props.toc!} class="max-h-none" />
|
|
46
|
+
<Show when={props.sidebarPromo}>
|
|
47
|
+
{(promo) => <SidebarPromo promo={promo()} />}
|
|
48
|
+
</Show>
|
|
49
|
+
</div>
|
|
50
|
+
</Container>
|
|
51
|
+
</Show>
|
|
52
|
+
</Container>
|
|
53
|
+
);
|