@hanzo/docs-core 16.4.3 → 16.5.3
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/README.md +3 -3
- package/dist/{advanced-BRT5Ij43.js → advanced-BH0syJ-M.js} +3 -4
- package/dist/{algolia-CQPXCnjV.js → algolia-C7Crg8-5.js} +2 -3
- package/dist/breadcrumb.d.ts +2 -3
- package/dist/breadcrumb.js +3 -4
- package/dist/{chunk-B-ezknvj.js → chunk-CaR5F9JI.js} +3 -3
- package/dist/content/github.d.ts +1 -2
- package/dist/content/github.js +1 -2
- package/dist/content/index.d.ts +3 -4
- package/dist/content/index.js +1 -2
- package/dist/content/mdx/preset-bundler.d.ts +9 -10
- package/dist/content/mdx/preset-bundler.js +2 -3
- package/dist/content/mdx/preset-runtime.d.ts +9 -10
- package/dist/content/mdx/preset-runtime.js +2 -3
- package/dist/content/toc.d.ts +1 -3
- package/dist/content/toc.js +4 -5
- package/dist/create-i18n-Cv3Cocbs.d.ts +51 -0
- package/dist/{definitions-DuxDer_c.d.ts → definitions-DSNTbAwC.d.ts} +1 -2
- package/dist/dynamic-link.d.ts +3 -4
- package/dist/dynamic-link.js +1 -3
- package/dist/{fetch-B5e9CFfN.js → fetch-HotVeLLF.js} +1 -2
- package/dist/framework/index.d.ts +5 -6
- package/dist/framework/index.js +18 -19
- package/dist/framework/next.d.ts +3 -4
- package/dist/framework/next.js +1 -2
- package/dist/framework/react-router.d.ts +1 -2
- package/dist/framework/react-router.js +1 -2
- package/dist/framework/tanstack.d.ts +4 -5
- package/dist/framework/tanstack.js +2 -3
- package/dist/framework/waku.d.ts +1 -2
- package/dist/framework/waku.js +1 -2
- package/dist/hast-utils-BmGqqmvo.js +15 -0
- package/dist/highlight/client.d.ts +2 -4
- package/dist/highlight/client.js +7 -13
- package/dist/highlight/config.d.ts +15 -0
- package/dist/highlight/config.js +18 -0
- package/dist/highlight/core/client.d.ts +31 -0
- package/dist/highlight/core/client.js +68 -0
- package/dist/highlight/core/index.d.ts +27 -0
- package/dist/highlight/core/index.js +69 -0
- package/dist/highlight/index.d.ts +34 -2
- package/dist/highlight/index.js +57 -2
- package/dist/i18n/index.d.ts +39 -1
- package/dist/i18n/index.js +1 -2
- package/dist/i18n/middleware.d.ts +2 -3
- package/dist/i18n/middleware.js +1 -2
- package/dist/{icon-BWwSDabM.js → icon-OtPFhyk1.js} +1 -2
- package/dist/link.d.ts +3 -4
- package/dist/link.js +1 -2
- package/dist/{mdast-utils-mc9-X-PK.js → mdast-utils-gJMY143g.js} +1 -2
- package/dist/mdx-plugins/codeblock-utils.d.ts +35 -1
- package/dist/mdx-plugins/codeblock-utils.js +2 -3
- package/dist/mdx-plugins/index.d.ts +18 -15
- package/dist/mdx-plugins/index.js +7 -5
- package/dist/mdx-plugins/rehype-code.core.d.ts +38 -0
- package/dist/mdx-plugins/rehype-code.core.js +104 -0
- package/dist/mdx-plugins/rehype-code.d.ts +18 -2
- package/dist/mdx-plugins/rehype-code.js +24 -3
- package/dist/mdx-plugins/rehype-toc.d.ts +16 -1
- package/dist/mdx-plugins/rehype-toc.js +127 -1
- package/dist/mdx-plugins/remark-admonition.d.ts +20 -1
- package/dist/mdx-plugins/remark-admonition.js +2 -3
- package/dist/mdx-plugins/remark-code-tab.d.ts +30 -1
- package/dist/mdx-plugins/remark-code-tab.js +4 -5
- package/dist/mdx-plugins/remark-directive-admonition.d.ts +34 -1
- package/dist/mdx-plugins/remark-directive-admonition.js +1 -2
- package/dist/mdx-plugins/remark-feedback-block.d.ts +51 -0
- package/dist/mdx-plugins/remark-feedback-block.js +47 -0
- package/dist/mdx-plugins/remark-gfm.d.ts +2 -2
- package/dist/mdx-plugins/remark-heading.d.ts +35 -1
- package/dist/mdx-plugins/remark-heading.js +2 -3
- package/dist/mdx-plugins/remark-image.d.ts +63 -1
- package/dist/mdx-plugins/remark-image.js +1 -2
- package/dist/mdx-plugins/remark-mdx-files.d.ts +55 -2
- package/dist/mdx-plugins/remark-mdx-files.js +103 -13
- package/dist/mdx-plugins/remark-mdx-mermaid.d.ts +15 -1
- package/dist/mdx-plugins/remark-mdx-mermaid.js +1 -2
- package/dist/mdx-plugins/remark-npm.d.ts +34 -1
- package/dist/mdx-plugins/remark-npm.js +1 -2
- package/dist/mdx-plugins/remark-steps.d.ts +26 -1
- package/dist/mdx-plugins/remark-steps.js +1 -2
- package/dist/mdx-plugins/remark-structure.d.ts +75 -1
- package/dist/mdx-plugins/remark-structure.js +7 -8
- package/dist/{mixedbread-DlByNYSd.js → mixedbread-Bx9drx9S.js} +6 -5
- package/dist/negotiation/index.d.ts +1 -2
- package/dist/negotiation/index.js +1 -2
- package/dist/{normalize-url-DP9-1I-S.js → normalize-url-DUHbcuVM.js} +2 -3
- package/dist/{orama-cloud-DH3g37zc.js → orama-cloud-ByznDyOk.js} +6 -7
- package/dist/orama-cloud-legacy-BbgJnf5f.js +81 -0
- package/dist/page-tree/index.d.ts +3 -45
- package/dist/page-tree/index.js +1 -1
- package/dist/{index-2U6Tl4--.d.ts → path-B77y3W0_.d.ts} +111 -98
- package/dist/{path-DHIjrDBP.js → path-D0Bwm6Fs.js} +2 -3
- package/dist/{remove-undefined-Cfs4o_mM.js → remove-undefined-CJm9cyrC.js} +1 -2
- package/dist/search/algolia.d.ts +66 -2
- package/dist/search/algolia.js +1 -2
- package/dist/search/client.d.ts +31 -8
- package/dist/search/client.js +27 -22
- package/dist/search/index.d.ts +1 -2
- package/dist/search/index.js +41 -1
- package/dist/search/orama-cloud-legacy.d.ts +77 -0
- package/dist/search/orama-cloud-legacy.js +49 -0
- package/dist/search/orama-cloud.d.ts +5 -9
- package/dist/search/orama-cloud.js +1 -2
- package/dist/search/server.d.ts +87 -4
- package/dist/search/server.js +7 -8
- package/dist/source/client/index.d.ts +13 -11
- package/dist/source/client/index.js +22 -13
- package/dist/source/index.d.ts +5 -3
- package/dist/source/index.js +428 -333
- package/dist/source/plugins/lucide-icons.d.ts +5 -4
- package/dist/source/plugins/lucide-icons.js +2 -3
- package/dist/source/plugins/slugs.d.ts +24 -2
- package/dist/source/plugins/slugs.js +2 -3
- package/dist/source/plugins/status-badges.d.ts +52 -0
- package/dist/source/plugins/status-badges.js +54 -0
- package/dist/source/schema.d.ts +1 -3
- package/dist/source/schema.js +1 -2
- package/dist/{static-Dq8pA8Ay.js → static-DTxK4eHk.js} +5 -6
- package/dist/toc.d.ts +5 -6
- package/dist/toc.js +1 -2
- package/dist/{rehype-code-CdiZ1Y6P.js → transformer-icon-BYedaeE8.js} +1 -96
- package/dist/transformer-icon-D7-6aFzt.d.ts +18 -0
- package/dist/types-BSnJn7kF.d.ts +6 -0
- package/dist/{util-CK2ykiif.d.ts → util-C60LmklF.d.ts} +1 -2
- package/dist/{util-s9piKHsk.js → util-De0ALHOx.js} +1 -2
- package/dist/utils/use-media-query.d.ts +1 -2
- package/dist/utils/use-media-query.js +1 -2
- package/dist/utils/use-on-change.d.ts +1 -2
- package/dist/utils/use-on-change.js +1 -2
- package/dist/{utils-DUvi2WkD.js → utils-Bc53B3CJ.js} +8 -7
- package/dist/utils-IgHyYnrz.d.ts +45 -0
- package/package.json +58 -28
- package/dist/advanced-BRT5Ij43.js.map +0 -1
- package/dist/algolia-CBBN8R6-.d.ts +0 -68
- package/dist/algolia-CBBN8R6-.d.ts.map +0 -1
- package/dist/algolia-CQPXCnjV.js.map +0 -1
- package/dist/breadcrumb.d.ts.map +0 -1
- package/dist/breadcrumb.js.map +0 -1
- package/dist/codeblock-utils-lld8UiQo.d.ts +0 -37
- package/dist/codeblock-utils-lld8UiQo.d.ts.map +0 -1
- package/dist/content/github.d.ts.map +0 -1
- package/dist/content/github.js.map +0 -1
- package/dist/content/index.d.ts.map +0 -1
- package/dist/content/index.js.map +0 -1
- package/dist/content/mdx/preset-bundler.d.ts.map +0 -1
- package/dist/content/mdx/preset-bundler.js.map +0 -1
- package/dist/content/mdx/preset-runtime.d.ts.map +0 -1
- package/dist/content/mdx/preset-runtime.js.map +0 -1
- package/dist/content/toc.d.ts.map +0 -1
- package/dist/content/toc.js.map +0 -1
- package/dist/definitions-DuxDer_c.d.ts.map +0 -1
- package/dist/dynamic-link.d.ts.map +0 -1
- package/dist/dynamic-link.js.map +0 -1
- package/dist/fetch-B5e9CFfN.js.map +0 -1
- package/dist/framework/index.d.ts.map +0 -1
- package/dist/framework/index.js.map +0 -1
- package/dist/framework/next.d.ts.map +0 -1
- package/dist/framework/next.js.map +0 -1
- package/dist/framework/react-router.d.ts.map +0 -1
- package/dist/framework/react-router.js.map +0 -1
- package/dist/framework/tanstack.d.ts.map +0 -1
- package/dist/framework/tanstack.js.map +0 -1
- package/dist/framework/waku.d.ts.map +0 -1
- package/dist/framework/waku.js.map +0 -1
- package/dist/highlight/client.d.ts.map +0 -1
- package/dist/highlight/client.js.map +0 -1
- package/dist/i18n/index.js.map +0 -1
- package/dist/i18n/middleware.d.ts.map +0 -1
- package/dist/i18n/middleware.js.map +0 -1
- package/dist/icon-BWwSDabM.js.map +0 -1
- package/dist/index-2U6Tl4--.d.ts.map +0 -1
- package/dist/index-Bw-DCOra.d.ts +0 -41
- package/dist/index-Bw-DCOra.d.ts.map +0 -1
- package/dist/link.d.ts.map +0 -1
- package/dist/link.js.map +0 -1
- package/dist/mdast-utils-mc9-X-PK.js.map +0 -1
- package/dist/mdx-plugins/codeblock-utils.js.map +0 -1
- package/dist/mdx-plugins/remark-admonition.js.map +0 -1
- package/dist/mdx-plugins/remark-code-tab.js.map +0 -1
- package/dist/mdx-plugins/remark-directive-admonition.js.map +0 -1
- package/dist/mdx-plugins/remark-heading.js.map +0 -1
- package/dist/mdx-plugins/remark-image.js.map +0 -1
- package/dist/mdx-plugins/remark-mdx-files.js.map +0 -1
- package/dist/mdx-plugins/remark-mdx-mermaid.js.map +0 -1
- package/dist/mdx-plugins/remark-npm.js.map +0 -1
- package/dist/mdx-plugins/remark-steps.js.map +0 -1
- package/dist/mdx-plugins/remark-structure.js.map +0 -1
- package/dist/mixedbread-DlByNYSd.js.map +0 -1
- package/dist/negotiation/index.d.ts.map +0 -1
- package/dist/negotiation/index.js.map +0 -1
- package/dist/normalize-url-DP9-1I-S.js.map +0 -1
- package/dist/orama-cloud-DH3g37zc.js.map +0 -1
- package/dist/page-tree/index.d.ts.map +0 -1
- package/dist/path-DHIjrDBP.js.map +0 -1
- package/dist/rehype-code-CdiZ1Y6P.js.map +0 -1
- package/dist/rehype-code-vVWG4-ej.d.ts +0 -58
- package/dist/rehype-code-vVWG4-ej.d.ts.map +0 -1
- package/dist/rehype-toc-DJvSyE0o.d.ts +0 -18
- package/dist/rehype-toc-DJvSyE0o.d.ts.map +0 -1
- package/dist/rehype-toc-DVwJcwvA.js +0 -143
- package/dist/rehype-toc-DVwJcwvA.js.map +0 -1
- package/dist/remark-admonition-DOwBWzsH.d.ts +0 -22
- package/dist/remark-admonition-DOwBWzsH.d.ts.map +0 -1
- package/dist/remark-code-tab-CXsYlims.d.ts +0 -32
- package/dist/remark-code-tab-CXsYlims.d.ts.map +0 -1
- package/dist/remark-directive-admonition-BCm_yiU9.d.ts +0 -36
- package/dist/remark-directive-admonition-BCm_yiU9.d.ts.map +0 -1
- package/dist/remark-gfm-CeWpMwyk.d.ts +0 -2
- package/dist/remark-heading-CXvCY0go.d.ts +0 -37
- package/dist/remark-heading-CXvCY0go.d.ts.map +0 -1
- package/dist/remark-image-CvUis4R1.d.ts +0 -65
- package/dist/remark-image-CvUis4R1.d.ts.map +0 -1
- package/dist/remark-mdx-files-DOYafA4x.d.ts +0 -42
- package/dist/remark-mdx-files-DOYafA4x.d.ts.map +0 -1
- package/dist/remark-mdx-mermaid-BdSUUiCG.d.ts +0 -17
- package/dist/remark-mdx-mermaid-BdSUUiCG.d.ts.map +0 -1
- package/dist/remark-npm-BIvIEKT2.d.ts +0 -36
- package/dist/remark-npm-BIvIEKT2.d.ts.map +0 -1
- package/dist/remark-steps-CHJN-rtm.d.ts +0 -28
- package/dist/remark-steps-CHJN-rtm.d.ts.map +0 -1
- package/dist/remark-structure-RZD2gGKp.d.ts +0 -77
- package/dist/remark-structure-RZD2gGKp.d.ts.map +0 -1
- package/dist/remove-undefined-Cfs4o_mM.js.map +0 -1
- package/dist/search/algolia.js.map +0 -1
- package/dist/search/client.d.ts.map +0 -1
- package/dist/search/client.js.map +0 -1
- package/dist/search/index.d.ts.map +0 -1
- package/dist/search/orama-cloud.d.ts.map +0 -1
- package/dist/search/orama-cloud.js.map +0 -1
- package/dist/search/server.js.map +0 -1
- package/dist/search-D6ChCLhY.js +0 -44
- package/dist/search-D6ChCLhY.js.map +0 -1
- package/dist/server-CPR_fgkH.d.ts +0 -133
- package/dist/server-CPR_fgkH.d.ts.map +0 -1
- package/dist/shiki-4oMYwHED.js +0 -80
- package/dist/shiki-4oMYwHED.js.map +0 -1
- package/dist/shiki-CIBQys54.d.ts +0 -33
- package/dist/shiki-CIBQys54.d.ts.map +0 -1
- package/dist/source/client/index.d.ts.map +0 -1
- package/dist/source/client/index.js.map +0 -1
- package/dist/source/index.js.map +0 -1
- package/dist/source/plugins/lucide-icons.d.ts.map +0 -1
- package/dist/source/plugins/lucide-icons.js.map +0 -1
- package/dist/source/plugins/slugs.js.map +0 -1
- package/dist/source/schema.d.ts.map +0 -1
- package/dist/source/schema.js.map +0 -1
- package/dist/static-Dq8pA8Ay.js.map +0 -1
- package/dist/toc.d.ts.map +0 -1
- package/dist/toc.js.map +0 -1
- package/dist/util-CK2ykiif.d.ts.map +0 -1
- package/dist/util-s9piKHsk.js.map +0 -1
- package/dist/utils/use-effect-event.d.ts +0 -11
- package/dist/utils/use-effect-event.d.ts.map +0 -1
- package/dist/utils/use-effect-event.js +0 -19
- package/dist/utils/use-effect-event.js.map +0 -1
- package/dist/utils/use-media-query.d.ts.map +0 -1
- package/dist/utils/use-media-query.js.map +0 -1
- package/dist/utils/use-on-change.d.ts.map +0 -1
- package/dist/utils/use-on-change.js.map +0 -1
- package/dist/utils-DUvi2WkD.js.map +0 -1
package/dist/source/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { t as normalizeUrl } from "../normalize-url-
|
|
2
|
-
import { c as visit } from "../utils-
|
|
3
|
-
import { a as path_exports, i as joinPath, n as dirname, o as slash, r as extname, s as splitPath, t as basename } from "../path-
|
|
1
|
+
import { t as normalizeUrl } from "../normalize-url-DUHbcuVM.js";
|
|
2
|
+
import { c as visit } from "../utils-Bc53B3CJ.js";
|
|
3
|
+
import { a as path_exports, i as joinPath, n as dirname, o as slash, r as extname, s as splitPath, t as basename } from "../path-D0Bwm6Fs.js";
|
|
4
4
|
import { getSlugs, slugsPlugin } from "./plugins/slugs.js";
|
|
5
|
-
import { t as iconPlugin } from "../icon-
|
|
5
|
+
import { t as iconPlugin } from "../icon-OtPFhyk1.js";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
|
|
8
8
|
//#region src/source/source.ts
|
|
9
9
|
function multiple(sources) {
|
|
10
10
|
const out = { files: [] };
|
|
11
|
-
for (const [type, source
|
|
11
|
+
for (const [type, source] of Object.entries(sources)) for (const file of source.files) out.files.push({
|
|
12
12
|
...file,
|
|
13
13
|
data: {
|
|
14
14
|
...file.data,
|
|
@@ -23,28 +23,28 @@ function source(config) {
|
|
|
23
23
|
/**
|
|
24
24
|
* update a source object in-place.
|
|
25
25
|
*/
|
|
26
|
-
function update(source
|
|
26
|
+
function update(source) {
|
|
27
27
|
return {
|
|
28
28
|
files(fn) {
|
|
29
|
-
source
|
|
29
|
+
source.files = fn(source.files);
|
|
30
30
|
return this;
|
|
31
31
|
},
|
|
32
32
|
page(fn) {
|
|
33
|
-
for (let i = 0; i < source
|
|
34
|
-
const file = source
|
|
35
|
-
if (file.type === "page") source
|
|
33
|
+
for (let i = 0; i < source.files.length; i++) {
|
|
34
|
+
const file = source.files[i];
|
|
35
|
+
if (file.type === "page") source.files[i] = fn(file);
|
|
36
36
|
}
|
|
37
37
|
return this;
|
|
38
38
|
},
|
|
39
39
|
meta(fn) {
|
|
40
|
-
for (let i = 0; i < source
|
|
41
|
-
const file = source
|
|
42
|
-
if (file.type === "meta") source
|
|
40
|
+
for (let i = 0; i < source.files.length; i++) {
|
|
41
|
+
const file = source.files[i];
|
|
42
|
+
if (file.type === "meta") source.files[i] = fn(file);
|
|
43
43
|
}
|
|
44
44
|
return this;
|
|
45
45
|
},
|
|
46
46
|
build() {
|
|
47
|
-
return source
|
|
47
|
+
return source;
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
}
|
|
@@ -63,22 +63,22 @@ var FileSystem = class {
|
|
|
63
63
|
for (const [k, v] of inherit.files) this.files.set(k, v);
|
|
64
64
|
} else this.folders.set("", []);
|
|
65
65
|
}
|
|
66
|
-
read(path
|
|
67
|
-
return this.files.get(path
|
|
66
|
+
read(path) {
|
|
67
|
+
return this.files.get(path);
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* get the direct children of folder (in virtual file path)
|
|
71
71
|
*/
|
|
72
|
-
readDir(path
|
|
73
|
-
return this.folders.get(path
|
|
72
|
+
readDir(path) {
|
|
73
|
+
return this.folders.get(path);
|
|
74
74
|
}
|
|
75
|
-
write(path
|
|
76
|
-
if (!this.files.has(path
|
|
77
|
-
const dir = dirname(path
|
|
75
|
+
write(path, file) {
|
|
76
|
+
if (!this.files.has(path)) {
|
|
77
|
+
const dir = dirname(path);
|
|
78
78
|
this.makeDir(dir);
|
|
79
|
-
this.readDir(dir)?.push(path
|
|
79
|
+
this.readDir(dir)?.push(path);
|
|
80
80
|
}
|
|
81
|
-
this.files.set(path
|
|
81
|
+
this.files.set(path, file);
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* Delete files at specified path.
|
|
@@ -86,12 +86,12 @@ var FileSystem = class {
|
|
|
86
86
|
* @param path - the target path.
|
|
87
87
|
* @param [recursive=false] - if set to `true`, it will also delete directories.
|
|
88
88
|
*/
|
|
89
|
-
delete(path
|
|
90
|
-
if (this.files.delete(path
|
|
89
|
+
delete(path, recursive = false) {
|
|
90
|
+
if (this.files.delete(path)) return true;
|
|
91
91
|
if (recursive) {
|
|
92
|
-
const folder = this.folders.get(path
|
|
92
|
+
const folder = this.folders.get(path);
|
|
93
93
|
if (!folder) return false;
|
|
94
|
-
this.folders.delete(path
|
|
94
|
+
this.folders.delete(path);
|
|
95
95
|
for (const child of folder) this.delete(child);
|
|
96
96
|
return true;
|
|
97
97
|
}
|
|
@@ -100,8 +100,8 @@ var FileSystem = class {
|
|
|
100
100
|
getFiles() {
|
|
101
101
|
return Array.from(this.files.keys());
|
|
102
102
|
}
|
|
103
|
-
makeDir(path
|
|
104
|
-
const segments = splitPath(path
|
|
103
|
+
makeDir(path) {
|
|
104
|
+
const segments = splitPath(path);
|
|
105
105
|
for (let i = 0; i < segments.length; i++) {
|
|
106
106
|
const segment = segments.slice(0, i + 1).join("/");
|
|
107
107
|
if (this.folders.has(segment)) continue;
|
|
@@ -117,39 +117,34 @@ function isLocaleValid(locale) {
|
|
|
117
117
|
return locale.length > 0 && !/\d+/.test(locale);
|
|
118
118
|
}
|
|
119
119
|
const parsers = {
|
|
120
|
-
dir(path
|
|
121
|
-
const [locale, ...segs] = path
|
|
120
|
+
dir(path) {
|
|
121
|
+
const [locale, ...segs] = path.split("/");
|
|
122
122
|
if (locale && segs.length > 0 && isLocaleValid(locale)) return [segs.join("/"), locale];
|
|
123
|
-
return [path
|
|
123
|
+
return [path];
|
|
124
124
|
},
|
|
125
|
-
dot(path
|
|
126
|
-
const dir = dirname(path
|
|
127
|
-
const parts = basename(path
|
|
128
|
-
if (parts.length < 3) return [path
|
|
125
|
+
dot(path) {
|
|
126
|
+
const dir = dirname(path);
|
|
127
|
+
const parts = basename(path).split(".");
|
|
128
|
+
if (parts.length < 3) return [path];
|
|
129
129
|
const [locale] = parts.splice(parts.length - 2, 1);
|
|
130
|
-
if (!isLocaleValid(locale)) return [path
|
|
130
|
+
if (!isLocaleValid(locale)) return [path];
|
|
131
131
|
return [joinPath(dir, parts.join(".")), locale];
|
|
132
132
|
},
|
|
133
|
-
none(path
|
|
134
|
-
return [path
|
|
133
|
+
none(path) {
|
|
134
|
+
return [path];
|
|
135
135
|
}
|
|
136
136
|
};
|
|
137
|
+
const EmptyLang = Symbol();
|
|
137
138
|
/**
|
|
138
|
-
*
|
|
139
|
-
* @returns a map of locale and its content storage.
|
|
139
|
+
* convert input files into virtual file system.
|
|
140
140
|
*
|
|
141
141
|
* in the storage, locale codes are removed from file paths, hence the same file will have same file paths in every storage.
|
|
142
142
|
*/
|
|
143
|
-
function
|
|
144
|
-
const { source
|
|
145
|
-
|
|
146
|
-
parser: "none",
|
|
147
|
-
languages: [defaultLanguage]
|
|
148
|
-
} } = loaderConfig;
|
|
149
|
-
const parser = parsers[i18n.parser ?? "dot"];
|
|
150
|
-
const storages = {};
|
|
143
|
+
function createContentStorageBuilder(loaderConfig) {
|
|
144
|
+
const { source, plugins = [], i18n } = loaderConfig;
|
|
145
|
+
const parser = i18n ? parsers[i18n.parser ?? "dot"] : parsers.none;
|
|
151
146
|
const normalized = /* @__PURE__ */ new Map();
|
|
152
|
-
for (const inputFile of source
|
|
147
|
+
for (const inputFile of source.files) {
|
|
153
148
|
let file;
|
|
154
149
|
if (inputFile.type === "page") file = {
|
|
155
150
|
format: "page",
|
|
@@ -164,7 +159,7 @@ function buildContentStorage(loaderConfig, defaultLanguage) {
|
|
|
164
159
|
absolutePath: inputFile.absolutePath,
|
|
165
160
|
data: inputFile.data
|
|
166
161
|
};
|
|
167
|
-
const [pathWithoutLocale, locale = i18n.defaultLanguage] = parser(file.path);
|
|
162
|
+
const [pathWithoutLocale, locale = i18n ? i18n.defaultLanguage : EmptyLang] = parser(file.path);
|
|
168
163
|
const list = normalized.get(locale) ?? [];
|
|
169
164
|
list.push({
|
|
170
165
|
pathWithoutLocale,
|
|
@@ -172,29 +167,37 @@ function buildContentStorage(loaderConfig, defaultLanguage) {
|
|
|
172
167
|
});
|
|
173
168
|
normalized.set(locale, list);
|
|
174
169
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
let storage;
|
|
179
|
-
if (fallbackLang && fallbackLang !== lang) {
|
|
180
|
-
scan(fallbackLang);
|
|
181
|
-
storage = new FileSystem(storages[fallbackLang]);
|
|
182
|
-
} else storage = new FileSystem();
|
|
183
|
-
for (const { pathWithoutLocale, file } of normalized.get(lang) ?? []) storage.write(pathWithoutLocale, file);
|
|
170
|
+
function makeStorage(locale, inherit) {
|
|
171
|
+
const storage = new FileSystem(inherit);
|
|
172
|
+
for (const { pathWithoutLocale, file } of normalized.get(locale) ?? []) storage.write(pathWithoutLocale, file);
|
|
184
173
|
const context = { storage };
|
|
185
174
|
for (const plugin of plugins) plugin.transformStorage?.(context);
|
|
186
|
-
|
|
175
|
+
return storage;
|
|
187
176
|
}
|
|
188
|
-
|
|
189
|
-
|
|
177
|
+
return {
|
|
178
|
+
i18n() {
|
|
179
|
+
const storages = {};
|
|
180
|
+
if (!i18n) return storages;
|
|
181
|
+
const fallbackLang = i18n.fallbackLanguage !== null ? i18n.fallbackLanguage ?? i18n.defaultLanguage : null;
|
|
182
|
+
function scan(lang) {
|
|
183
|
+
if (storages[lang]) return storages[lang];
|
|
184
|
+
return storages[lang] = makeStorage(lang, fallbackLang && fallbackLang !== lang ? scan(fallbackLang) : void 0);
|
|
185
|
+
}
|
|
186
|
+
for (const lang of i18n.languages) scan(lang);
|
|
187
|
+
return storages;
|
|
188
|
+
},
|
|
189
|
+
single() {
|
|
190
|
+
return makeStorage(EmptyLang);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
190
193
|
}
|
|
191
194
|
/**
|
|
192
195
|
* @param path - Relative path
|
|
193
196
|
* @returns Normalized path, with no trailing/leading slashes
|
|
194
197
|
* @throws Throws error if path starts with `./` or `../`
|
|
195
198
|
*/
|
|
196
|
-
function normalizePath(path
|
|
197
|
-
const segments = splitPath(slash(path
|
|
199
|
+
function normalizePath(path) {
|
|
200
|
+
const segments = splitPath(slash(path));
|
|
198
201
|
if (segments[0] === "." || segments[0] === "..") throw new Error("It must not start with './' or '../'");
|
|
199
202
|
return segments.join("/");
|
|
200
203
|
}
|
|
@@ -203,28 +206,39 @@ function normalizePath(path$1) {
|
|
|
203
206
|
//#region src/source/page-tree/transformer-fallback.ts
|
|
204
207
|
function transformerFallback() {
|
|
205
208
|
const addedFiles = /* @__PURE__ */ new Set();
|
|
209
|
+
function shouldIgnore(context) {
|
|
210
|
+
return context.custom?._fallback === true;
|
|
211
|
+
}
|
|
206
212
|
return {
|
|
207
213
|
root(root) {
|
|
214
|
+
if (shouldIgnore(this)) return root;
|
|
208
215
|
const isolatedStorage = new FileSystem();
|
|
216
|
+
if (addedFiles.size === this.storage.files.size) return root;
|
|
209
217
|
for (const file of this.storage.getFiles()) {
|
|
210
218
|
if (addedFiles.has(file)) continue;
|
|
211
|
-
|
|
212
|
-
if (content) isolatedStorage.write(file, content);
|
|
219
|
+
isolatedStorage.write(file, this.storage.read(file));
|
|
213
220
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
221
|
+
root.fallback = new PageTreeBuilder(isolatedStorage, {
|
|
222
|
+
idPrefix: this.idPrefix ? `fallback:${this.idPrefix}` : "fallback",
|
|
223
|
+
url: this.getUrl,
|
|
224
|
+
noRef: this.noRef,
|
|
225
|
+
transformers: this.transformers,
|
|
226
|
+
generateFallback: false,
|
|
227
|
+
context: {
|
|
228
|
+
...this.custom,
|
|
229
|
+
_fallback: true
|
|
230
|
+
}
|
|
231
|
+
}).root();
|
|
220
232
|
addedFiles.clear();
|
|
221
233
|
return root;
|
|
222
234
|
},
|
|
223
235
|
file(node, file) {
|
|
236
|
+
if (shouldIgnore(this)) return node;
|
|
224
237
|
if (file) addedFiles.add(file);
|
|
225
238
|
return node;
|
|
226
239
|
},
|
|
227
240
|
folder(node, _dir, metaPath) {
|
|
241
|
+
if (shouldIgnore(this)) return node;
|
|
228
242
|
if (metaPath) addedFiles.add(metaPath);
|
|
229
243
|
return node;
|
|
230
244
|
}
|
|
@@ -240,211 +254,262 @@ const rest = "...";
|
|
|
240
254
|
const restReversed = "z...a";
|
|
241
255
|
const extractPrefix = "...";
|
|
242
256
|
const excludePrefix = "!";
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
return out;
|
|
257
|
+
var PageTreeBuilder = class {
|
|
258
|
+
constructor(input, options) {
|
|
259
|
+
this.flattenPathToFullPath = /* @__PURE__ */ new Map();
|
|
260
|
+
this.transformers = [];
|
|
261
|
+
this.pathToNode = /* @__PURE__ */ new Map();
|
|
262
|
+
this.unfinished = /* @__PURE__ */ new WeakSet();
|
|
263
|
+
this.ownerMap = /* @__PURE__ */ new Map();
|
|
264
|
+
this._nextId = 0;
|
|
265
|
+
const { transformers, url, context, generateFallback = true, idPrefix = "", noRef = false } = options;
|
|
266
|
+
if (transformers) this.transformers.push(...transformers);
|
|
267
|
+
if (generateFallback) this.transformers.push(transformerFallback());
|
|
268
|
+
this.ctx = {
|
|
269
|
+
builder: this,
|
|
270
|
+
idPrefix,
|
|
271
|
+
getUrl: url,
|
|
272
|
+
storage: void 0,
|
|
273
|
+
noRef,
|
|
274
|
+
transformers: this.transformers,
|
|
275
|
+
custom: context
|
|
276
|
+
};
|
|
277
|
+
if (Array.isArray(input)) {
|
|
278
|
+
const [locale, storages] = input;
|
|
279
|
+
this.ctx.storage = this.storage = storages[locale];
|
|
280
|
+
this.ctx.locale = locale;
|
|
281
|
+
this.ctx.storages = storages;
|
|
282
|
+
} else this.ctx.storage = this.storage = input;
|
|
283
|
+
for (const file of this.storage.getFiles()) {
|
|
284
|
+
const content = this.storage.read(file);
|
|
285
|
+
const flattenPath = file.substring(0, file.length - extname(file).length);
|
|
286
|
+
this.flattenPathToFullPath.set(flattenPath + "." + content.format, file);
|
|
275
287
|
}
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
function createFlattenPathResolver(storage) {
|
|
279
|
-
const map = /* @__PURE__ */ new Map();
|
|
280
|
-
const files = storage.getFiles();
|
|
281
|
-
for (const file of files) {
|
|
282
|
-
const content = storage.read(file);
|
|
283
|
-
const flattenPath = file.substring(0, file.length - extname(file).length);
|
|
284
|
-
map.set(flattenPath + "." + content.format, file);
|
|
285
288
|
}
|
|
286
|
-
|
|
287
|
-
return
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
function createPageTreeBuilderUtils(ctx) {
|
|
291
|
-
const resolveFlattenPath = createFlattenPathResolver(ctx.storage);
|
|
292
|
-
const visitedPaths = /* @__PURE__ */ new Set();
|
|
293
|
-
function nextNodeId(localId = ctx.generateNodeId()) {
|
|
294
|
-
return `${ctx.rootId}:${localId}`;
|
|
289
|
+
resolveFlattenPath(name, format) {
|
|
290
|
+
return this.flattenPathToFullPath.get(name + "." + format) ?? name;
|
|
295
291
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
let filename = item;
|
|
350
|
-
if (isExcept) filename = item.slice(1);
|
|
351
|
-
else if (isExtract) filename = item.slice(3);
|
|
352
|
-
const path$1 = resolveFlattenPath(joinPath(folderPath, filename), "page");
|
|
353
|
-
if (isExcept) {
|
|
354
|
-
visitedPaths.add(path$1);
|
|
355
|
-
return [];
|
|
356
|
-
}
|
|
357
|
-
const dirNode = this.folder(path$1, false);
|
|
358
|
-
if (dirNode) return isExtract ? dirNode.children : [dirNode];
|
|
359
|
-
const fileNode = this.file(path$1);
|
|
360
|
-
return fileNode ? [fileNode] : [];
|
|
361
|
-
},
|
|
362
|
-
folder(folderPath, isGlobalRoot) {
|
|
363
|
-
const { storage, options, transformers } = ctx;
|
|
364
|
-
const files = storage.readDir(folderPath);
|
|
365
|
-
if (!files) return;
|
|
366
|
-
const metaPath = resolveFlattenPath(joinPath(folderPath, "meta"), "meta");
|
|
367
|
-
const indexPath = resolveFlattenPath(joinPath(folderPath, "index"), "page");
|
|
368
|
-
let meta = storage.read(metaPath);
|
|
369
|
-
if (meta && meta.format !== "meta") meta = void 0;
|
|
370
|
-
const metadata = meta?.data ?? {};
|
|
371
|
-
const { root = isGlobalRoot, pages } = metadata;
|
|
372
|
-
let index;
|
|
373
|
-
let children;
|
|
374
|
-
if (pages) {
|
|
375
|
-
const resolved = pages.flatMap((item) => this.resolveFolderItem(folderPath, item));
|
|
376
|
-
if (!root && !visitedPaths.has(indexPath)) index = this.file(indexPath);
|
|
377
|
-
for (let i = 0; i < resolved.length; i++) {
|
|
378
|
-
const item = resolved[i];
|
|
379
|
-
if (item !== rest && item !== restReversed) continue;
|
|
380
|
-
const items = this.buildPaths(files.filter((file) => !visitedPaths.has(file)), item === restReversed);
|
|
381
|
-
resolved.splice(i, 1, ...items);
|
|
382
|
-
break;
|
|
383
|
-
}
|
|
384
|
-
children = resolved;
|
|
385
|
-
} else {
|
|
386
|
-
if (!root && !visitedPaths.has(indexPath)) index = this.file(indexPath);
|
|
387
|
-
children = this.buildPaths(files.filter((file) => !visitedPaths.has(file)));
|
|
292
|
+
/**
|
|
293
|
+
* try to register as the owner of `node`.
|
|
294
|
+
*
|
|
295
|
+
* when a node is referenced by multiple folders, this determines which folder they should belong to.
|
|
296
|
+
*
|
|
297
|
+
* @returns whether the owner owns the node.
|
|
298
|
+
*/
|
|
299
|
+
own(ownerPath, node, priority) {
|
|
300
|
+
if (this.unfinished.has(node)) return false;
|
|
301
|
+
const existing = this.ownerMap.get(node);
|
|
302
|
+
if (!existing) {
|
|
303
|
+
this.ownerMap.set(node, {
|
|
304
|
+
owner: ownerPath,
|
|
305
|
+
priority
|
|
306
|
+
});
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
if (existing.owner === ownerPath) {
|
|
310
|
+
existing.priority = Math.max(existing.priority, priority);
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
if (existing.priority >= priority) return false;
|
|
314
|
+
const folder = this.pathToNode.get(existing.owner);
|
|
315
|
+
if (folder && folder.type === "folder") if (folder.index === node) delete folder.index;
|
|
316
|
+
else {
|
|
317
|
+
const idx = folder.children.indexOf(node);
|
|
318
|
+
if (idx !== -1) folder.children.splice(idx, 1);
|
|
319
|
+
}
|
|
320
|
+
existing.owner = ownerPath;
|
|
321
|
+
existing.priority = priority;
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
transferOwner(ownerPath, node) {
|
|
325
|
+
const existing = this.ownerMap.get(node);
|
|
326
|
+
if (existing) existing.owner = ownerPath;
|
|
327
|
+
}
|
|
328
|
+
generateId(localId = `_${this._nextId++}`) {
|
|
329
|
+
let id = localId;
|
|
330
|
+
if (this.ctx.locale) id = `${this.ctx.locale}:${id}`;
|
|
331
|
+
if (this.ctx.idPrefix) id = `${this.ctx.idPrefix}:${id}`;
|
|
332
|
+
return id;
|
|
333
|
+
}
|
|
334
|
+
buildPaths(paths, filter, reversed = false) {
|
|
335
|
+
const items = [];
|
|
336
|
+
const folders = [];
|
|
337
|
+
const sortedPaths = paths.sort((a, b) => reversed ? b.localeCompare(a) : a.localeCompare(b));
|
|
338
|
+
for (const path of sortedPaths) {
|
|
339
|
+
if (filter && !filter(path)) continue;
|
|
340
|
+
const fileNode = this.file(path);
|
|
341
|
+
if (fileNode) {
|
|
342
|
+
if (basename(path, extname(path)) === "index") items.unshift(fileNode);
|
|
343
|
+
else items.push(fileNode);
|
|
344
|
+
continue;
|
|
388
345
|
}
|
|
346
|
+
const dirNode = this.folder(path);
|
|
347
|
+
if (dirNode) folders.push(dirNode);
|
|
348
|
+
}
|
|
349
|
+
items.push(...folders);
|
|
350
|
+
return items;
|
|
351
|
+
}
|
|
352
|
+
resolveFolderItem(folderPath, item, outputArray, excludedPaths) {
|
|
353
|
+
if (item === rest || item === restReversed) {
|
|
354
|
+
outputArray.push(item);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
let match = separator.exec(item);
|
|
358
|
+
if (match?.groups) {
|
|
389
359
|
let node = {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
})(),
|
|
395
|
-
icon: metadata.icon ?? index?.icon,
|
|
396
|
-
root: metadata.root,
|
|
397
|
-
defaultOpen: metadata.defaultOpen,
|
|
398
|
-
description: metadata.description,
|
|
399
|
-
collapsible: metadata.collapsible,
|
|
400
|
-
index,
|
|
401
|
-
children,
|
|
402
|
-
$id: nextNodeId(folderPath),
|
|
403
|
-
$ref: !options.noRef && meta ? { metaFile: metaPath } : void 0
|
|
360
|
+
$id: this.generateId(),
|
|
361
|
+
type: "separator",
|
|
362
|
+
icon: match.groups.icon,
|
|
363
|
+
name: match.groups.name
|
|
404
364
|
};
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
node = transformer.folder.call(ctx, node, folderPath, metaPath);
|
|
365
|
+
for (const transformer of this.transformers) {
|
|
366
|
+
if (!transformer.separator) continue;
|
|
367
|
+
node = transformer.separator.call(this.ctx, node);
|
|
409
368
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
$id: nextNodeId(path$1),
|
|
369
|
+
outputArray.push(node);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
match = link.exec(item);
|
|
373
|
+
if (match?.groups) {
|
|
374
|
+
const { icon, url, name, external } = match.groups;
|
|
375
|
+
let node = {
|
|
376
|
+
$id: this.generateId(),
|
|
419
377
|
type: "page",
|
|
420
|
-
name: title ?? pathToName(basename(path$1, extname(path$1))),
|
|
421
|
-
description,
|
|
422
378
|
icon,
|
|
423
|
-
|
|
424
|
-
|
|
379
|
+
name,
|
|
380
|
+
url
|
|
425
381
|
};
|
|
426
|
-
|
|
427
|
-
for (const transformer of transformers) {
|
|
382
|
+
if (external) node.external = true;
|
|
383
|
+
for (const transformer of this.transformers) {
|
|
428
384
|
if (!transformer.file) continue;
|
|
429
|
-
|
|
385
|
+
node = transformer.file.call(this.ctx, node);
|
|
430
386
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
387
|
+
outputArray.push(node);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (item.startsWith(excludePrefix)) {
|
|
391
|
+
const path = joinPath(folderPath, item.slice(1));
|
|
392
|
+
excludedPaths.add(path);
|
|
393
|
+
excludedPaths.add(this.resolveFlattenPath(path, "page"));
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (item.startsWith(extractPrefix)) {
|
|
397
|
+
const path = joinPath(folderPath, item.slice(3));
|
|
398
|
+
const node = this.folder(path);
|
|
399
|
+
if (!node) return;
|
|
400
|
+
const children = node.index ? [node.index, ...node.children] : node.children;
|
|
401
|
+
if (this.own(folderPath, node, 2)) {
|
|
402
|
+
for (const child of children) {
|
|
403
|
+
this.transferOwner(folderPath, child);
|
|
404
|
+
outputArray.push(child);
|
|
405
|
+
}
|
|
406
|
+
excludedPaths.add(path);
|
|
407
|
+
} else for (const child of children) if (this.own(folderPath, child, 2)) outputArray.push(child);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
let path = joinPath(folderPath, item);
|
|
411
|
+
let node = this.folder(path);
|
|
412
|
+
if (!node) {
|
|
413
|
+
path = this.resolveFlattenPath(path, "page");
|
|
414
|
+
node = this.file(path);
|
|
415
|
+
}
|
|
416
|
+
if (!node || !this.own(folderPath, node, 2)) return;
|
|
417
|
+
outputArray.push(node);
|
|
418
|
+
excludedPaths.add(path);
|
|
419
|
+
}
|
|
420
|
+
folder(folderPath) {
|
|
421
|
+
const cached = this.pathToNode.get(folderPath);
|
|
422
|
+
if (cached) return cached;
|
|
423
|
+
const files = this.storage.readDir(folderPath);
|
|
424
|
+
if (!files) return;
|
|
425
|
+
const isGlobalRoot = folderPath === "";
|
|
426
|
+
const metaPath = this.resolveFlattenPath(joinPath(folderPath, "meta"), "meta");
|
|
427
|
+
const indexPath = this.resolveFlattenPath(joinPath(folderPath, "index"), "page");
|
|
428
|
+
let meta = this.storage.read(metaPath);
|
|
429
|
+
if (meta && meta.format !== "meta") meta = void 0;
|
|
430
|
+
const metadata = meta?.data ?? {};
|
|
431
|
+
let node = {
|
|
432
|
+
type: "folder",
|
|
433
|
+
name: null,
|
|
434
|
+
root: metadata.root,
|
|
435
|
+
defaultOpen: metadata.defaultOpen,
|
|
436
|
+
description: metadata.description,
|
|
437
|
+
collapsible: metadata.collapsible,
|
|
438
|
+
children: [],
|
|
439
|
+
$id: this.generateId(folderPath),
|
|
440
|
+
$ref: !this.ctx.noRef && meta ? { metaFile: metaPath } : void 0
|
|
441
|
+
};
|
|
442
|
+
this.pathToNode.set(folderPath, node);
|
|
443
|
+
this.unfinished.add(node);
|
|
444
|
+
if (!(metadata.root ?? isGlobalRoot)) {
|
|
445
|
+
const file = this.file(indexPath);
|
|
446
|
+
if (file && this.own(folderPath, file, 0)) node.index = file;
|
|
447
|
+
}
|
|
448
|
+
if (metadata.pages) {
|
|
449
|
+
const outputArray = [];
|
|
450
|
+
const excludedPaths = /* @__PURE__ */ new Set();
|
|
451
|
+
for (const item of metadata.pages) this.resolveFolderItem(folderPath, item, outputArray, excludedPaths);
|
|
452
|
+
if (excludedPaths.has(indexPath)) delete node.index;
|
|
453
|
+
else if (node.index) excludedPaths.add(indexPath);
|
|
454
|
+
for (const item of outputArray) {
|
|
455
|
+
if (item !== rest && item !== restReversed) {
|
|
456
|
+
node.children.push(item);
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
const resolvedItem = this.buildPaths(files, (file) => !excludedPaths.has(file), item === restReversed);
|
|
460
|
+
for (const child of resolvedItem) if (this.own(folderPath, child, 0)) node.children.push(child);
|
|
443
461
|
}
|
|
444
|
-
|
|
462
|
+
} else for (const item of this.buildPaths(files, node.index ? (file) => file !== indexPath : void 0)) if (this.own(folderPath, item, 0)) node.children.push(item);
|
|
463
|
+
node.icon = metadata.icon ?? node.index?.icon;
|
|
464
|
+
node.name = metadata.title ?? node.index?.name;
|
|
465
|
+
this.unfinished.delete(node);
|
|
466
|
+
if (!node.name) {
|
|
467
|
+
const folderName = basename(folderPath);
|
|
468
|
+
node.name = pathToName(group.exec(folderName)?.[1] ?? folderName);
|
|
445
469
|
}
|
|
446
|
-
|
|
447
|
-
|
|
470
|
+
for (const transformer of this.transformers) {
|
|
471
|
+
if (!transformer.folder) continue;
|
|
472
|
+
node = transformer.folder.call(this.ctx, node, folderPath, meta ? metaPath : void 0);
|
|
473
|
+
}
|
|
474
|
+
this.pathToNode.set(folderPath, node);
|
|
475
|
+
return node;
|
|
476
|
+
}
|
|
477
|
+
file(path) {
|
|
478
|
+
const cached = this.pathToNode.get(path);
|
|
479
|
+
if (cached) return cached;
|
|
480
|
+
const page = this.storage.read(path);
|
|
481
|
+
if (!page || page.format !== "page") return;
|
|
482
|
+
const { title, description, icon } = page.data;
|
|
483
|
+
let item = {
|
|
484
|
+
$id: this.generateId(path),
|
|
485
|
+
type: "page",
|
|
486
|
+
name: title ?? pathToName(basename(path, extname(path))),
|
|
487
|
+
description,
|
|
488
|
+
icon,
|
|
489
|
+
url: this.ctx.getUrl(page.slugs, this.ctx.locale),
|
|
490
|
+
$ref: !this.ctx.noRef ? { file: path } : void 0
|
|
491
|
+
};
|
|
492
|
+
for (const transformer of this.transformers) {
|
|
493
|
+
if (!transformer.file) continue;
|
|
494
|
+
item = transformer.file.call(this.ctx, item, path);
|
|
495
|
+
}
|
|
496
|
+
this.pathToNode.set(path, item);
|
|
497
|
+
return item;
|
|
498
|
+
}
|
|
499
|
+
root(id = "root", path = "") {
|
|
500
|
+
const folder = this.folder(path);
|
|
501
|
+
let root = {
|
|
502
|
+
$id: this.generateId(id),
|
|
503
|
+
name: folder?.name || "Docs",
|
|
504
|
+
children: folder ? folder.children : []
|
|
505
|
+
};
|
|
506
|
+
for (const transformer of this.transformers) {
|
|
507
|
+
if (!transformer.root) continue;
|
|
508
|
+
root = transformer.root.call(this.ctx, root);
|
|
509
|
+
}
|
|
510
|
+
return root;
|
|
511
|
+
}
|
|
512
|
+
};
|
|
448
513
|
/**
|
|
449
514
|
* Get item name from file name
|
|
450
515
|
*
|
|
@@ -460,35 +525,54 @@ function pathToName(name) {
|
|
|
460
525
|
|
|
461
526
|
//#endregion
|
|
462
527
|
//#region src/source/loader.ts
|
|
463
|
-
function
|
|
464
|
-
const
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
528
|
+
function createPageIndexer({ url }) {
|
|
529
|
+
const pages = /* @__PURE__ */ new Map();
|
|
530
|
+
const pathToMeta = /* @__PURE__ */ new Map();
|
|
531
|
+
const pathToPage = /* @__PURE__ */ new Map();
|
|
532
|
+
return {
|
|
533
|
+
scan(storage, lang) {
|
|
534
|
+
for (const filePath of storage.getFiles()) {
|
|
535
|
+
const item = storage.read(filePath);
|
|
536
|
+
const prefix = lang ? `${lang}.` : ".";
|
|
537
|
+
const path = prefix + filePath;
|
|
538
|
+
if (item.format === "meta") {
|
|
539
|
+
pathToMeta.set(path, {
|
|
540
|
+
path: item.path,
|
|
541
|
+
absolutePath: item.absolutePath,
|
|
542
|
+
data: item.data
|
|
543
|
+
});
|
|
544
|
+
continue;
|
|
545
|
+
}
|
|
546
|
+
const page = {
|
|
547
|
+
absolutePath: item.absolutePath,
|
|
548
|
+
path: item.path,
|
|
549
|
+
url: url(item.slugs, lang),
|
|
550
|
+
slugs: item.slugs,
|
|
551
|
+
data: item.data,
|
|
552
|
+
locale: lang
|
|
553
|
+
};
|
|
554
|
+
pathToPage.set(path, page);
|
|
555
|
+
pages.set(prefix + page.slugs.join("/"), page);
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
getPage(path, lang = "") {
|
|
559
|
+
return pathToPage.get(`${lang}.${path}`);
|
|
560
|
+
},
|
|
561
|
+
getMeta(path, lang = "") {
|
|
562
|
+
return pathToMeta.get(`${lang}.${path}`);
|
|
563
|
+
},
|
|
564
|
+
getPageBySlugs(slugs, lang = "") {
|
|
565
|
+
let page = pages.get(`${lang}.${slugs.join("/")}`);
|
|
566
|
+
if (page) return page;
|
|
567
|
+
page = pages.get(`${lang}.${slugs.map(decodeURI).join("/")}`);
|
|
568
|
+
if (page) return page;
|
|
569
|
+
},
|
|
570
|
+
getPages(lang) {
|
|
571
|
+
const out = [];
|
|
572
|
+
for (const [key, value] of pages.entries()) if (lang === void 0 || key.startsWith(`${lang}.`)) out.push(value);
|
|
573
|
+
return out;
|
|
479
574
|
}
|
|
480
|
-
|
|
481
|
-
absolutePath: item.absolutePath,
|
|
482
|
-
path: item.path,
|
|
483
|
-
url: url(item.slugs, lang),
|
|
484
|
-
slugs: item.slugs,
|
|
485
|
-
data: item.data,
|
|
486
|
-
locale: lang
|
|
487
|
-
};
|
|
488
|
-
result.pathToPage.set(path$1, page);
|
|
489
|
-
result.pages.set(`${lang}.${page.slugs.join("/")}`, page);
|
|
490
|
-
}
|
|
491
|
-
return result;
|
|
575
|
+
};
|
|
492
576
|
}
|
|
493
577
|
function createGetUrl(baseUrl, i18n) {
|
|
494
578
|
const baseSlugs = baseUrl.split("/");
|
|
@@ -505,33 +589,43 @@ function createGetUrl(baseUrl, i18n) {
|
|
|
505
589
|
function loader(...args) {
|
|
506
590
|
const loaderConfig = args.length === 2 ? resolveConfig(args[0], args[1]) : resolveConfig(args[0].source, args[0]);
|
|
507
591
|
const { i18n } = loaderConfig;
|
|
508
|
-
const
|
|
509
|
-
const
|
|
510
|
-
|
|
511
|
-
const
|
|
592
|
+
const storage = i18n ? createContentStorageBuilder(loaderConfig).i18n() : createContentStorageBuilder(loaderConfig).single();
|
|
593
|
+
const indexer = createPageIndexer(loaderConfig);
|
|
594
|
+
if (storage instanceof FileSystem) indexer.scan(storage);
|
|
595
|
+
else for (const locale in storage) indexer.scan(storage[locale], locale);
|
|
512
596
|
let pageTrees;
|
|
513
597
|
function getPageTrees() {
|
|
514
|
-
|
|
598
|
+
if (pageTrees) return pageTrees;
|
|
599
|
+
const { plugins = [], url, pageTree: pageTreeConfig } = loaderConfig;
|
|
600
|
+
const transformers = [];
|
|
601
|
+
if (pageTreeConfig?.transformers) transformers.push(...pageTreeConfig.transformers);
|
|
602
|
+
for (const plugin of plugins) if (plugin.transformPageTree) transformers.push(plugin.transformPageTree);
|
|
603
|
+
const options = {
|
|
604
|
+
url,
|
|
605
|
+
...pageTreeConfig,
|
|
606
|
+
transformers
|
|
607
|
+
};
|
|
608
|
+
if (storage instanceof FileSystem) return pageTrees = new PageTreeBuilder(storage, options).root();
|
|
609
|
+
else {
|
|
610
|
+
const out = {};
|
|
611
|
+
for (const locale in storage) out[locale] = new PageTreeBuilder([locale, storage], options).root();
|
|
612
|
+
return pageTrees = out;
|
|
613
|
+
}
|
|
515
614
|
}
|
|
516
615
|
return {
|
|
517
616
|
_i18n: i18n,
|
|
518
617
|
get pageTree() {
|
|
519
|
-
|
|
520
|
-
return i18n ? trees : trees[defaultLanguage];
|
|
618
|
+
return getPageTrees();
|
|
521
619
|
},
|
|
522
620
|
set pageTree(v) {
|
|
523
|
-
|
|
524
|
-
else {
|
|
525
|
-
pageTrees ??= {};
|
|
526
|
-
pageTrees[defaultLanguage] = v;
|
|
527
|
-
}
|
|
621
|
+
pageTrees = v;
|
|
528
622
|
},
|
|
529
|
-
getPageByHref(href, { dir = "", language = defaultLanguage } = {}) {
|
|
623
|
+
getPageByHref(href, { dir = "", language = i18n?.defaultLanguage } = {}) {
|
|
530
624
|
const [value, hash] = href.split("#", 2);
|
|
531
625
|
let target;
|
|
532
626
|
if (value.startsWith("./")) {
|
|
533
|
-
const path
|
|
534
|
-
target =
|
|
627
|
+
const path = joinPath(dir, value);
|
|
628
|
+
target = indexer.getPage(path, language);
|
|
535
629
|
} else target = this.getPages(language).find((item) => item.url === value);
|
|
536
630
|
if (target) return {
|
|
537
631
|
page: target,
|
|
@@ -549,9 +643,7 @@ function loader(...args) {
|
|
|
549
643
|
return href;
|
|
550
644
|
},
|
|
551
645
|
getPages(language) {
|
|
552
|
-
|
|
553
|
-
for (const [key, value] of walker.pages.entries()) if (language === void 0 || key.startsWith(`${language}.`)) pages.push(value);
|
|
554
|
-
return pages;
|
|
646
|
+
return indexer.getPages(language);
|
|
555
647
|
},
|
|
556
648
|
getLanguages() {
|
|
557
649
|
const list = [];
|
|
@@ -562,25 +654,26 @@ function loader(...args) {
|
|
|
562
654
|
});
|
|
563
655
|
return list;
|
|
564
656
|
},
|
|
565
|
-
getPage(slugs = [], language = defaultLanguage) {
|
|
566
|
-
|
|
567
|
-
if (page) return page;
|
|
568
|
-
page = walker.pages.get(`${language}.${slugs.map(decodeURI).join("/")}`);
|
|
569
|
-
if (page) return page;
|
|
657
|
+
getPage(slugs = [], language = i18n?.defaultLanguage) {
|
|
658
|
+
return indexer.getPageBySlugs(slugs, language);
|
|
570
659
|
},
|
|
571
|
-
getNodeMeta(node, language = defaultLanguage) {
|
|
660
|
+
getNodeMeta(node, language = i18n?.defaultLanguage) {
|
|
572
661
|
const ref = node.$ref?.metaFile;
|
|
573
662
|
if (!ref) return;
|
|
574
|
-
return
|
|
663
|
+
return indexer.getMeta(ref, language);
|
|
575
664
|
},
|
|
576
|
-
getNodePage(node, language = defaultLanguage) {
|
|
665
|
+
getNodePage(node, language = i18n?.defaultLanguage) {
|
|
577
666
|
const ref = node.$ref?.file;
|
|
578
667
|
if (!ref) return;
|
|
579
|
-
return
|
|
668
|
+
return indexer.getPage(ref, language);
|
|
580
669
|
},
|
|
581
|
-
getPageTree(locale
|
|
582
|
-
|
|
583
|
-
|
|
670
|
+
getPageTree(locale) {
|
|
671
|
+
if (i18n) {
|
|
672
|
+
const trees = getPageTrees();
|
|
673
|
+
if (locale && trees[locale]) return trees[locale];
|
|
674
|
+
return trees[i18n.defaultLanguage];
|
|
675
|
+
}
|
|
676
|
+
return getPageTrees();
|
|
584
677
|
},
|
|
585
678
|
generateParams(slug, lang) {
|
|
586
679
|
if (i18n) return this.getLanguages().flatMap((entry) => entry.pages.map((page) => ({
|
|
@@ -591,21 +684,24 @@ function loader(...args) {
|
|
|
591
684
|
},
|
|
592
685
|
async serializePageTree(tree) {
|
|
593
686
|
const { renderToString } = await import("react-dom/server.edge");
|
|
594
|
-
return
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
687
|
+
return {
|
|
688
|
+
$hanzo_docs_loader: "page-tree",
|
|
689
|
+
data: visit(tree, (node) => {
|
|
690
|
+
node = { ...node };
|
|
691
|
+
if ("icon" in node && node.icon) node.icon = renderToString(node.icon);
|
|
692
|
+
if (node.name) node.name = renderToString(node.name);
|
|
693
|
+
if ("children" in node) node.children = [...node.children];
|
|
694
|
+
return node;
|
|
695
|
+
})
|
|
696
|
+
};
|
|
601
697
|
}
|
|
602
698
|
};
|
|
603
699
|
}
|
|
604
|
-
function resolveConfig(source
|
|
700
|
+
function resolveConfig(source, { slugs, icon, plugins = [], baseUrl, url, ...base }) {
|
|
605
701
|
let config = {
|
|
606
702
|
...base,
|
|
607
703
|
url: url ? (...args) => normalizeUrl(url(...args)) : createGetUrl(baseUrl, base.i18n),
|
|
608
|
-
source
|
|
704
|
+
source,
|
|
609
705
|
plugins: buildPlugins([
|
|
610
706
|
icon && iconPlugin(icon),
|
|
611
707
|
...typeof plugins === "function" ? plugins({ typedPlugin: (plugin) => plugin }) : plugins,
|
|
@@ -632,5 +728,4 @@ function buildPlugins(plugins, sort = true) {
|
|
|
632
728
|
}
|
|
633
729
|
|
|
634
730
|
//#endregion
|
|
635
|
-
export { FileSystem, path_exports as PathUtils, createGetUrl, getSlugs, loader, multiple, source, update };
|
|
636
|
-
//# sourceMappingURL=index.js.map
|
|
731
|
+
export { FileSystem, path_exports as PathUtils, createGetUrl, getSlugs, loader, multiple, source, update };
|