@hanzo/docs-core 16.2.5
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 +5 -0
- package/dist/algolia-IZEDLPHE.js +58 -0
- package/dist/breadcrumb.d.ts +46 -0
- package/dist/breadcrumb.js +81 -0
- package/dist/chunk-5PMI7QDD.js +220 -0
- package/dist/chunk-ADBHPKXG.js +78 -0
- package/dist/chunk-APKPSBSB.js +74 -0
- package/dist/chunk-CH7YHH7V.js +222 -0
- package/dist/chunk-EFVXL2PP.js +144 -0
- package/dist/chunk-EMWGTXSW.js +19 -0
- package/dist/chunk-FAEPKD7U.js +20 -0
- package/dist/chunk-FUUVPEA5.js +29 -0
- package/dist/chunk-GINBKBVQ.js +12 -0
- package/dist/chunk-GLRQBLGN.js +59 -0
- package/dist/chunk-JUF4WZ6G.js +117 -0
- package/dist/chunk-K4WNLOVQ.js +75 -0
- package/dist/chunk-L4JKQWCM.js +131 -0
- package/dist/chunk-MA6O2UUE.js +50 -0
- package/dist/chunk-ONG4RVCR.js +8 -0
- package/dist/chunk-OTD7MV33.js +53 -0
- package/dist/chunk-PFNP6PEB.js +11 -0
- package/dist/chunk-QJRXMG4S.js +275 -0
- package/dist/chunk-SH7BNTG7.js +38 -0
- package/dist/chunk-TWIDBWFG.js +84 -0
- package/dist/chunk-U67V476Y.js +35 -0
- package/dist/chunk-VLSDGCJE.js +47 -0
- package/dist/chunk-W6WTLKRA.js +73 -0
- package/dist/chunk-X2HFD5QJ.js +275 -0
- package/dist/chunk-XJ6ZQNEX.js +91 -0
- package/dist/chunk-XN2LKXFZ.js +101 -0
- package/dist/chunk-XOFXGHS4.js +93 -0
- package/dist/chunk-XZSI7AHE.js +67 -0
- package/dist/chunk-YVVDKJ2H.js +34 -0
- package/dist/chunk-ZMWYLUDP.js +21 -0
- package/dist/content/github.d.ts +40 -0
- package/dist/content/github.js +44 -0
- package/dist/content/index.d.ts +16 -0
- package/dist/content/index.js +30 -0
- package/dist/content/mdx/preset-bundler.d.ts +31 -0
- package/dist/content/mdx/preset-bundler.js +72 -0
- package/dist/content/mdx/preset-runtime.d.ts +31 -0
- package/dist/content/mdx/preset-runtime.js +71 -0
- package/dist/content/toc.d.ts +21 -0
- package/dist/content/toc.js +22 -0
- package/dist/definitions-pJ7PybYY.d.ts +60 -0
- package/dist/dynamic-link.d.ts +12 -0
- package/dist/dynamic-link.js +32 -0
- package/dist/fetch-IBTWQCJR.js +22 -0
- package/dist/framework/index.d.ts +41 -0
- package/dist/framework/index.js +18 -0
- package/dist/framework/next.d.ts +12 -0
- package/dist/framework/next.js +31 -0
- package/dist/framework/react-router.d.ts +12 -0
- package/dist/framework/react-router.js +59 -0
- package/dist/framework/tanstack.d.ts +15 -0
- package/dist/framework/tanstack.js +72 -0
- package/dist/framework/waku.d.ts +12 -0
- package/dist/framework/waku.js +63 -0
- package/dist/highlight/client.d.ts +15 -0
- package/dist/highlight/client.js +18 -0
- package/dist/highlight/index.d.ts +30 -0
- package/dist/highlight/index.js +13 -0
- package/dist/i18n/index.d.ts +39 -0
- package/dist/i18n/index.js +9 -0
- package/dist/i18n/middleware.d.ts +34 -0
- package/dist/i18n/middleware.js +76 -0
- package/dist/link.d.ts +18 -0
- package/dist/link.js +9 -0
- package/dist/loader-BvlPPJX0.d.ts +321 -0
- package/dist/mdx-plugins/codeblock-utils.d.ts +29 -0
- package/dist/mdx-plugins/codeblock-utils.js +9 -0
- package/dist/mdx-plugins/index.d.ts +20 -0
- package/dist/mdx-plugins/index.js +73 -0
- package/dist/mdx-plugins/rehype-code.d.ts +55 -0
- package/dist/mdx-plugins/rehype-code.js +15 -0
- package/dist/mdx-plugins/rehype-toc.d.ts +14 -0
- package/dist/mdx-plugins/rehype-toc.js +7 -0
- package/dist/mdx-plugins/remark-admonition.d.ts +20 -0
- package/dist/mdx-plugins/remark-admonition.js +8 -0
- package/dist/mdx-plugins/remark-code-tab.d.ts +30 -0
- package/dist/mdx-plugins/remark-code-tab.js +8 -0
- package/dist/mdx-plugins/remark-directive-admonition.d.ts +27 -0
- package/dist/mdx-plugins/remark-directive-admonition.js +7 -0
- package/dist/mdx-plugins/remark-gfm.d.ts +1 -0
- package/dist/mdx-plugins/remark-gfm.js +7 -0
- package/dist/mdx-plugins/remark-heading.d.ts +31 -0
- package/dist/mdx-plugins/remark-heading.js +8 -0
- package/dist/mdx-plugins/remark-image.d.ts +57 -0
- package/dist/mdx-plugins/remark-image.js +7 -0
- package/dist/mdx-plugins/remark-mdx-files.d.ts +40 -0
- package/dist/mdx-plugins/remark-mdx-files.js +7 -0
- package/dist/mdx-plugins/remark-mdx-mermaid.d.ts +15 -0
- package/dist/mdx-plugins/remark-mdx-mermaid.js +7 -0
- package/dist/mdx-plugins/remark-npm.d.ts +31 -0
- package/dist/mdx-plugins/remark-npm.js +8 -0
- package/dist/mdx-plugins/remark-steps.d.ts +23 -0
- package/dist/mdx-plugins/remark-steps.js +7 -0
- package/dist/mdx-plugins/remark-structure.d.ts +71 -0
- package/dist/mdx-plugins/remark-structure.js +12 -0
- package/dist/mixedbread-RAHDVXGJ.js +118 -0
- package/dist/negotiation/index.d.ts +19 -0
- package/dist/negotiation/index.js +11 -0
- package/dist/orama-cloud-UZAPMPFV.js +93 -0
- package/dist/page-tree/index.d.ts +33 -0
- package/dist/page-tree/index.js +17 -0
- package/dist/search/algolia.d.ts +69 -0
- package/dist/search/algolia.js +71 -0
- package/dist/search/client.d.ts +140 -0
- package/dist/search/client.js +99 -0
- package/dist/search/index.d.ts +26 -0
- package/dist/search/index.js +7 -0
- package/dist/search/orama-cloud.d.ts +79 -0
- package/dist/search/orama-cloud.js +60 -0
- package/dist/search/server.d.ts +136 -0
- package/dist/search/server.js +400 -0
- package/dist/source/client/index.d.ts +16 -0
- package/dist/source/client/index.js +41 -0
- package/dist/source/index.d.ts +42 -0
- package/dist/source/index.js +776 -0
- package/dist/source/plugins/lucide-icons.d.ts +14 -0
- package/dist/source/plugins/lucide-icons.js +23 -0
- package/dist/source/schema.d.ts +26 -0
- package/dist/source/schema.js +25 -0
- package/dist/static-A2YJ5TXV.js +62 -0
- package/dist/toc.d.ts +43 -0
- package/dist/toc.js +151 -0
- package/dist/util-bZU2QeJ2.d.ts +6 -0
- package/dist/utils/use-effect-event.d.ts +9 -0
- package/dist/utils/use-effect-event.js +16 -0
- package/dist/utils/use-media-query.d.ts +3 -0
- package/dist/utils/use-media-query.js +23 -0
- package/dist/utils/use-on-change.d.ts +8 -0
- package/dist/utils/use-on-change.js +7 -0
- package/package.json +222 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Fuma
|
|
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,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContentHighlighter
|
|
3
|
+
} from "./chunk-OTD7MV33.js";
|
|
4
|
+
import "./chunk-U67V476Y.js";
|
|
5
|
+
|
|
6
|
+
// src/search/client/algolia.ts
|
|
7
|
+
function groupResults(hits) {
|
|
8
|
+
const grouped = [];
|
|
9
|
+
const scannedUrls = /* @__PURE__ */ new Set();
|
|
10
|
+
for (const hit of hits) {
|
|
11
|
+
if (!scannedUrls.has(hit.url)) {
|
|
12
|
+
scannedUrls.add(hit.url);
|
|
13
|
+
grouped.push({
|
|
14
|
+
id: hit.url,
|
|
15
|
+
type: "page",
|
|
16
|
+
breadcrumbs: hit.breadcrumbs,
|
|
17
|
+
url: hit.url,
|
|
18
|
+
content: hit.title
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
grouped.push({
|
|
22
|
+
id: hit.objectID,
|
|
23
|
+
type: hit.content === hit.section ? "heading" : "text",
|
|
24
|
+
url: hit.section_id ? `${hit.url}#${hit.section_id}` : hit.url,
|
|
25
|
+
content: hit.content
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return grouped;
|
|
29
|
+
}
|
|
30
|
+
async function searchDocs(query, { indexName, onSearch, client, locale, tag }) {
|
|
31
|
+
if (query.trim().length === 0) return [];
|
|
32
|
+
const result = onSearch ? await onSearch(query, tag, locale) : await client.searchForHits({
|
|
33
|
+
requests: [
|
|
34
|
+
{
|
|
35
|
+
type: "default",
|
|
36
|
+
indexName,
|
|
37
|
+
query,
|
|
38
|
+
distinct: 5,
|
|
39
|
+
hitsPerPage: 10,
|
|
40
|
+
filters: tag ? `tag:${tag}` : void 0
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
const highlighter = createContentHighlighter(query);
|
|
45
|
+
return groupResults(result.results[0].hits).flatMap((hit) => {
|
|
46
|
+
if (hit.type === "page") {
|
|
47
|
+
return {
|
|
48
|
+
...hit,
|
|
49
|
+
contentWithHighlights: hit.contentWithHighlights ?? highlighter.highlight(hit.content)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return [];
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
groupResults,
|
|
57
|
+
searchDocs
|
|
58
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { R as Root, N as Node } from './definitions-pJ7PybYY.js';
|
|
3
|
+
|
|
4
|
+
interface BreadcrumbItem {
|
|
5
|
+
name: ReactNode;
|
|
6
|
+
url?: string;
|
|
7
|
+
}
|
|
8
|
+
interface BreadcrumbOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Include the root folders in the breadcrumb items array.
|
|
11
|
+
*
|
|
12
|
+
* @defaultValue false
|
|
13
|
+
*/
|
|
14
|
+
includeRoot?: boolean | {
|
|
15
|
+
/**
|
|
16
|
+
* Specify the url of root
|
|
17
|
+
*/
|
|
18
|
+
url: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Include the page itself in the breadcrumb items array
|
|
22
|
+
*
|
|
23
|
+
* @defaultValue false
|
|
24
|
+
*/
|
|
25
|
+
includePage?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Count separator as an item
|
|
28
|
+
*
|
|
29
|
+
* @defaultValue false
|
|
30
|
+
*/
|
|
31
|
+
includeSeparator?: boolean;
|
|
32
|
+
}
|
|
33
|
+
declare function useBreadcrumb(url: string, tree: Root, options?: BreadcrumbOptions): BreadcrumbItem[];
|
|
34
|
+
declare function getBreadcrumbItems(url: string, tree: Root, options?: BreadcrumbOptions): BreadcrumbItem[];
|
|
35
|
+
declare function getBreadcrumbItemsFromPath(tree: Root, path: Node[], options: BreadcrumbOptions): BreadcrumbItem[];
|
|
36
|
+
/**
|
|
37
|
+
* Search the path of a node in the tree by a specified url
|
|
38
|
+
*
|
|
39
|
+
* - When the page doesn't exist, return null
|
|
40
|
+
*
|
|
41
|
+
* @returns The path to the target node from root
|
|
42
|
+
* @internal Don't use this on your own
|
|
43
|
+
*/
|
|
44
|
+
declare function searchPath(nodes: Node[], url: string): Node[] | null;
|
|
45
|
+
|
|
46
|
+
export { type BreadcrumbItem, type BreadcrumbOptions, getBreadcrumbItems, getBreadcrumbItemsFromPath, searchPath, useBreadcrumb };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeUrl
|
|
3
|
+
} from "./chunk-PFNP6PEB.js";
|
|
4
|
+
import {
|
|
5
|
+
findPath
|
|
6
|
+
} from "./chunk-L4JKQWCM.js";
|
|
7
|
+
import "./chunk-U67V476Y.js";
|
|
8
|
+
|
|
9
|
+
// src/breadcrumb.tsx
|
|
10
|
+
import { useMemo } from "react";
|
|
11
|
+
function useBreadcrumb(url, tree, options) {
|
|
12
|
+
return useMemo(
|
|
13
|
+
() => getBreadcrumbItems(url, tree, options),
|
|
14
|
+
[tree, url, options]
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
function getBreadcrumbItems(url, tree, options = {}) {
|
|
18
|
+
return getBreadcrumbItemsFromPath(
|
|
19
|
+
tree,
|
|
20
|
+
searchPath(tree.children, url) ?? [],
|
|
21
|
+
options
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
function getBreadcrumbItemsFromPath(tree, path, options) {
|
|
25
|
+
const {
|
|
26
|
+
includePage = false,
|
|
27
|
+
includeSeparator = false,
|
|
28
|
+
includeRoot = false
|
|
29
|
+
} = options;
|
|
30
|
+
let items = [];
|
|
31
|
+
for (let i = 0; i < path.length; i++) {
|
|
32
|
+
const item = path[i];
|
|
33
|
+
switch (item.type) {
|
|
34
|
+
case "page":
|
|
35
|
+
if (includePage)
|
|
36
|
+
items.push({
|
|
37
|
+
name: item.name,
|
|
38
|
+
url: item.url
|
|
39
|
+
});
|
|
40
|
+
break;
|
|
41
|
+
case "folder":
|
|
42
|
+
if (item.root && !includeRoot) {
|
|
43
|
+
items = [];
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
if (i === path.length - 1 || item.index !== path[i + 1]) {
|
|
47
|
+
items.push({
|
|
48
|
+
name: item.name,
|
|
49
|
+
url: item.index?.url
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
case "separator":
|
|
54
|
+
if (item.name && includeSeparator)
|
|
55
|
+
items.push({
|
|
56
|
+
name: item.name
|
|
57
|
+
});
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (includeRoot) {
|
|
62
|
+
items.unshift({
|
|
63
|
+
name: tree.name,
|
|
64
|
+
url: typeof includeRoot === "object" ? includeRoot.url : void 0
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return items;
|
|
68
|
+
}
|
|
69
|
+
function searchPath(nodes, url) {
|
|
70
|
+
const normalizedUrl = normalizeUrl(url);
|
|
71
|
+
return findPath(
|
|
72
|
+
nodes,
|
|
73
|
+
(node) => node.type === "page" && node.url === normalizedUrl
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
getBreadcrumbItems,
|
|
78
|
+
getBreadcrumbItemsFromPath,
|
|
79
|
+
searchPath,
|
|
80
|
+
useBreadcrumb
|
|
81
|
+
};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// src/mdx-plugins/remark-image.ts
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { visit } from "unist-util-visit";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
var VALID_BLUR_EXT = [".jpeg", ".png", ".webp", ".avif", ".jpg"];
|
|
6
|
+
var EXTERNAL_URL_REGEX = /^https?:\/\//;
|
|
7
|
+
function remarkImage({
|
|
8
|
+
placeholder = "blur",
|
|
9
|
+
external = true,
|
|
10
|
+
useImport = true,
|
|
11
|
+
onError = "error",
|
|
12
|
+
publicDir = path.join(process.cwd(), "public")
|
|
13
|
+
} = {}) {
|
|
14
|
+
return async (tree, file) => {
|
|
15
|
+
const importsToInject = [];
|
|
16
|
+
const promises = [];
|
|
17
|
+
async function onImage(src, node) {
|
|
18
|
+
const attributes = [
|
|
19
|
+
{
|
|
20
|
+
type: "mdxJsxAttribute",
|
|
21
|
+
name: "alt",
|
|
22
|
+
value: node.alt ?? "image"
|
|
23
|
+
}
|
|
24
|
+
];
|
|
25
|
+
if (node.title) {
|
|
26
|
+
attributes.push({
|
|
27
|
+
type: "mdxJsxAttribute",
|
|
28
|
+
name: "title",
|
|
29
|
+
value: node.title
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (src.type === "file" && useImport) {
|
|
33
|
+
const variableName = `__img${importsToInject.length}`;
|
|
34
|
+
const hasBlur = placeholder === "blur" && VALID_BLUR_EXT.some((ext) => src.file.endsWith(ext));
|
|
35
|
+
if (!file.dirname) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"When `useImport` is enabled, you must specify `dirname` in the VFile passed to compiler."
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
importsToInject.push({
|
|
41
|
+
variableName,
|
|
42
|
+
importPath: getImportPath(src.file, file.dirname)
|
|
43
|
+
});
|
|
44
|
+
attributes.push({
|
|
45
|
+
type: "mdxJsxAttribute",
|
|
46
|
+
name: "src",
|
|
47
|
+
value: {
|
|
48
|
+
type: "mdxJsxAttributeValueExpression",
|
|
49
|
+
value: variableName,
|
|
50
|
+
data: {
|
|
51
|
+
estree: {
|
|
52
|
+
body: [
|
|
53
|
+
{
|
|
54
|
+
type: "ExpressionStatement",
|
|
55
|
+
expression: { type: "Identifier", name: variableName }
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
type: "Program",
|
|
59
|
+
sourceType: "script"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const out = {
|
|
65
|
+
children: [],
|
|
66
|
+
type: "mdxJsxFlowElement",
|
|
67
|
+
name: "img",
|
|
68
|
+
attributes
|
|
69
|
+
};
|
|
70
|
+
if (hasBlur) {
|
|
71
|
+
out.attributes.push({
|
|
72
|
+
type: "mdxJsxAttribute",
|
|
73
|
+
name: "placeholder",
|
|
74
|
+
value: "blur"
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
const size = await getImageSize(src, external).catch((e) => {
|
|
80
|
+
throw new Error(
|
|
81
|
+
`[Remark Image] Failed obtain image size for ${node.url} (public directory configured as ${publicDir})`,
|
|
82
|
+
{
|
|
83
|
+
cause: e
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
if (!size) return;
|
|
88
|
+
attributes.push(
|
|
89
|
+
{
|
|
90
|
+
type: "mdxJsxAttribute",
|
|
91
|
+
name: "src",
|
|
92
|
+
// `src` doesn't support file paths, we can use `node.url` for files and let the underlying framework handle it
|
|
93
|
+
value: src.type === "url" ? src.url.toString() : node.url
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
type: "mdxJsxAttribute",
|
|
97
|
+
name: "width",
|
|
98
|
+
value: size.width.toString()
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
type: "mdxJsxAttribute",
|
|
102
|
+
name: "height",
|
|
103
|
+
value: size.height.toString()
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
return {
|
|
107
|
+
type: "mdxJsxFlowElement",
|
|
108
|
+
name: "img",
|
|
109
|
+
attributes,
|
|
110
|
+
children: []
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
visit(tree, "image", (node) => {
|
|
114
|
+
const src = parseSrc(decodeURI(node.url), publicDir, file.dirname);
|
|
115
|
+
if (!src) return;
|
|
116
|
+
const task = onImage(src, node).catch((e) => {
|
|
117
|
+
if (onError === "ignore" || node.url.endsWith(".svg")) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (onError === "hide") {
|
|
121
|
+
return {
|
|
122
|
+
type: "mdxJsxFlowElement",
|
|
123
|
+
name: null,
|
|
124
|
+
attributes: [],
|
|
125
|
+
children: []
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (onError === "error") throw e;
|
|
129
|
+
onError(e);
|
|
130
|
+
}).then((res) => {
|
|
131
|
+
if (res) Object.assign(node, res);
|
|
132
|
+
});
|
|
133
|
+
promises.push(task);
|
|
134
|
+
});
|
|
135
|
+
await Promise.all(promises);
|
|
136
|
+
if (importsToInject.length === 0) return;
|
|
137
|
+
const imports = importsToInject.map(
|
|
138
|
+
({ variableName, importPath }) => ({
|
|
139
|
+
type: "mdxjsEsm",
|
|
140
|
+
data: {
|
|
141
|
+
estree: {
|
|
142
|
+
body: [
|
|
143
|
+
{
|
|
144
|
+
type: "ImportDeclaration",
|
|
145
|
+
source: { type: "Literal", value: importPath },
|
|
146
|
+
specifiers: [
|
|
147
|
+
{
|
|
148
|
+
type: "ImportDefaultSpecifier",
|
|
149
|
+
local: { type: "Identifier", name: variableName }
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
);
|
|
158
|
+
tree.children.unshift(...imports);
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function getImportPath(file, dir) {
|
|
162
|
+
const relative2 = path.relative(dir, file).replaceAll(path.sep, "/");
|
|
163
|
+
return relative2.startsWith("../") ? relative2 : `./${relative2}`;
|
|
164
|
+
}
|
|
165
|
+
function parseSrc(src, publicDir, dir) {
|
|
166
|
+
if (src.startsWith("file:///"))
|
|
167
|
+
return { type: "file", file: fileURLToPath(src) };
|
|
168
|
+
if (EXTERNAL_URL_REGEX.test(src)) {
|
|
169
|
+
return {
|
|
170
|
+
type: "url",
|
|
171
|
+
url: new URL(src)
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (src.startsWith("/")) {
|
|
175
|
+
if (EXTERNAL_URL_REGEX.test(publicDir)) {
|
|
176
|
+
const url = new URL(publicDir);
|
|
177
|
+
const segs = [...url.pathname.split("/"), ...src.split("/")].filter(
|
|
178
|
+
(v) => v.length > 0
|
|
179
|
+
);
|
|
180
|
+
url.pathname = `/${segs.join("/")}`;
|
|
181
|
+
return { type: "url", url };
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
type: "file",
|
|
185
|
+
file: path.join(publicDir, src)
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
if (!dir) {
|
|
189
|
+
console.warn(
|
|
190
|
+
`[Remark Image] found relative path ${src} but missing 'dirname' in VFile, this image will be skipped for now.`
|
|
191
|
+
);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
type: "file",
|
|
196
|
+
file: path.join(dir, src)
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
async function getImageSize(src, onExternal) {
|
|
200
|
+
if (src.type === "file") {
|
|
201
|
+
const { imageSizeFromFile } = await import("image-size/fromFile");
|
|
202
|
+
return imageSizeFromFile(src.file);
|
|
203
|
+
}
|
|
204
|
+
if (onExternal === false) return;
|
|
205
|
+
const { timeout } = typeof onExternal === "object" ? onExternal : {};
|
|
206
|
+
const res = await fetch(src.url, {
|
|
207
|
+
signal: typeof timeout === "number" ? AbortSignal.timeout(timeout) : void 0
|
|
208
|
+
});
|
|
209
|
+
if (!res.ok) {
|
|
210
|
+
throw new Error(
|
|
211
|
+
`[Remark Image] Failed to fetch ${src.url} (${res.status}): ${await res.text()}`
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
const { imageSize } = await import("image-size");
|
|
215
|
+
return imageSize(new Uint8Array(await res.arrayBuffer()));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export {
|
|
219
|
+
remarkImage
|
|
220
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/mdx-plugins/remark-mdx-files.ts
|
|
2
|
+
import { visit } from "unist-util-visit";
|
|
3
|
+
function parseFileTree(code) {
|
|
4
|
+
const lines = code.split(/\r?\n/);
|
|
5
|
+
const stack = /* @__PURE__ */ new Map();
|
|
6
|
+
for (const line of lines) {
|
|
7
|
+
let depth = 0;
|
|
8
|
+
let name = line;
|
|
9
|
+
let match;
|
|
10
|
+
while (match = /(?:├──|│|└──)\s*/.exec(name)) {
|
|
11
|
+
name = name.slice(match[0].length);
|
|
12
|
+
depth++;
|
|
13
|
+
}
|
|
14
|
+
if (!name) continue;
|
|
15
|
+
const node = name.endsWith("/") ? { type: "folder", name, children: [], depth } : { type: "file", name, depth };
|
|
16
|
+
let parent;
|
|
17
|
+
for (let i = depth - 1; i >= 0 && !parent; i--) {
|
|
18
|
+
parent = stack.get(i);
|
|
19
|
+
}
|
|
20
|
+
stack.set(depth, node);
|
|
21
|
+
if (!parent) continue;
|
|
22
|
+
if (parent.type === "file") {
|
|
23
|
+
Object.assign(parent, {
|
|
24
|
+
type: "folder",
|
|
25
|
+
children: []
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
parent.children.push(node);
|
|
29
|
+
}
|
|
30
|
+
return stack.get(0);
|
|
31
|
+
}
|
|
32
|
+
function defaultToMDX(node, depth = 0) {
|
|
33
|
+
if (depth === 0) {
|
|
34
|
+
return {
|
|
35
|
+
type: "mdxJsxFlowElement",
|
|
36
|
+
name: "Files",
|
|
37
|
+
attributes: [],
|
|
38
|
+
children: [defaultToMDX(node, depth + 1)]
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const attributes = [
|
|
42
|
+
{ type: "mdxJsxAttribute", name: "name", value: node.name }
|
|
43
|
+
];
|
|
44
|
+
if (node.type === "file") {
|
|
45
|
+
return {
|
|
46
|
+
type: "mdxJsxFlowElement",
|
|
47
|
+
attributes,
|
|
48
|
+
children: [],
|
|
49
|
+
name: "File"
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
attributes.push({
|
|
53
|
+
type: "mdxJsxAttribute",
|
|
54
|
+
name: "defaultOpen",
|
|
55
|
+
value: null
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
type: "mdxJsxFlowElement",
|
|
59
|
+
attributes,
|
|
60
|
+
name: "Folder",
|
|
61
|
+
children: node.children.map((item) => defaultToMDX(item, depth + 1))
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function remarkMdxFiles(options = {}) {
|
|
65
|
+
const { lang = "files", toMdx = defaultToMDX } = options;
|
|
66
|
+
return (tree) => {
|
|
67
|
+
visit(tree, "code", (node) => {
|
|
68
|
+
if (node.lang !== lang || !node.value) return;
|
|
69
|
+
const fileTree = parseFileTree(node.value);
|
|
70
|
+
if (!fileTree) return;
|
|
71
|
+
Object.assign(node, toMdx(fileTree));
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
remarkMdxFiles
|
|
78
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/mdx-plugins/remark-directive-admonition.ts
|
|
2
|
+
import { visit } from "unist-util-visit";
|
|
3
|
+
function remarkDirectiveAdmonition({
|
|
4
|
+
tags: {
|
|
5
|
+
CalloutContainer = "CalloutContainer",
|
|
6
|
+
CalloutTitle = "CalloutTitle",
|
|
7
|
+
CalloutDescription = "CalloutDescription"
|
|
8
|
+
} = {},
|
|
9
|
+
types = {
|
|
10
|
+
note: "info",
|
|
11
|
+
tip: "info",
|
|
12
|
+
info: "info",
|
|
13
|
+
warn: "warning",
|
|
14
|
+
warning: "warning",
|
|
15
|
+
danger: "error",
|
|
16
|
+
success: "success"
|
|
17
|
+
}
|
|
18
|
+
} = {}) {
|
|
19
|
+
return (tree) => {
|
|
20
|
+
visit(tree, "containerDirective", (node) => {
|
|
21
|
+
if (!(node.name in types)) return;
|
|
22
|
+
const attributes = [
|
|
23
|
+
{
|
|
24
|
+
type: "mdxJsxAttribute",
|
|
25
|
+
name: "type",
|
|
26
|
+
value: types[node.name]
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
for (const [k, v] of Object.entries(node.attributes ?? {})) {
|
|
30
|
+
attributes.push({
|
|
31
|
+
type: "mdxJsxAttribute",
|
|
32
|
+
name: k,
|
|
33
|
+
value: v
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const titleNodes = [];
|
|
37
|
+
const descriptionNodes = [];
|
|
38
|
+
for (const item of node.children) {
|
|
39
|
+
if (item.type === "paragraph" && item.data?.directiveLabel) {
|
|
40
|
+
titleNodes.push(...item.children);
|
|
41
|
+
} else {
|
|
42
|
+
descriptionNodes.push(item);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const children = [];
|
|
46
|
+
if (titleNodes.length > 0) {
|
|
47
|
+
children.push({
|
|
48
|
+
type: "mdxJsxFlowElement",
|
|
49
|
+
name: CalloutTitle,
|
|
50
|
+
attributes: [],
|
|
51
|
+
children: titleNodes
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (descriptionNodes.length > 0) {
|
|
55
|
+
children.push({
|
|
56
|
+
type: "mdxJsxFlowElement",
|
|
57
|
+
name: CalloutDescription,
|
|
58
|
+
attributes: [],
|
|
59
|
+
children: descriptionNodes
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
Object.assign(node, {
|
|
63
|
+
type: "mdxJsxFlowElement",
|
|
64
|
+
attributes,
|
|
65
|
+
name: CalloutContainer,
|
|
66
|
+
children
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export {
|
|
73
|
+
remarkDirectiveAdmonition
|
|
74
|
+
};
|