@hanzo/docs-core 16.5.0 → 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.
Files changed (262) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -3
  3. package/dist/{advanced-BRT5Ij43.js → advanced-BH0syJ-M.js} +3 -4
  4. package/dist/{algolia-CQPXCnjV.js → algolia-C7Crg8-5.js} +2 -3
  5. package/dist/breadcrumb.d.ts +2 -3
  6. package/dist/breadcrumb.js +3 -4
  7. package/dist/{chunk-B-ezknvj.js → chunk-CaR5F9JI.js} +3 -3
  8. package/dist/content/github.d.ts +1 -2
  9. package/dist/content/github.js +1 -2
  10. package/dist/content/index.d.ts +3 -4
  11. package/dist/content/index.js +1 -2
  12. package/dist/content/mdx/preset-bundler.d.ts +9 -10
  13. package/dist/content/mdx/preset-bundler.js +2 -3
  14. package/dist/content/mdx/preset-runtime.d.ts +9 -10
  15. package/dist/content/mdx/preset-runtime.js +2 -3
  16. package/dist/content/toc.d.ts +1 -3
  17. package/dist/content/toc.js +4 -5
  18. package/dist/create-i18n-Cv3Cocbs.d.ts +51 -0
  19. package/dist/{definitions-DuxDer_c.d.ts → definitions-DSNTbAwC.d.ts} +1 -2
  20. package/dist/dynamic-link.d.ts +3 -4
  21. package/dist/dynamic-link.js +1 -3
  22. package/dist/{fetch-B5e9CFfN.js → fetch-HotVeLLF.js} +1 -2
  23. package/dist/framework/index.d.ts +5 -6
  24. package/dist/framework/index.js +18 -19
  25. package/dist/framework/next.d.ts +3 -4
  26. package/dist/framework/next.js +1 -2
  27. package/dist/framework/react-router.d.ts +3 -4
  28. package/dist/framework/react-router.js +1 -2
  29. package/dist/framework/tanstack.d.ts +3 -4
  30. package/dist/framework/tanstack.js +1 -2
  31. package/dist/framework/waku.d.ts +3 -4
  32. package/dist/framework/waku.js +1 -2
  33. package/dist/hast-utils-BmGqqmvo.js +15 -0
  34. package/dist/highlight/client.d.ts +2 -4
  35. package/dist/highlight/client.js +7 -13
  36. package/dist/highlight/config.d.ts +15 -0
  37. package/dist/highlight/config.js +18 -0
  38. package/dist/highlight/core/client.d.ts +31 -0
  39. package/dist/highlight/core/client.js +68 -0
  40. package/dist/highlight/core/index.d.ts +27 -0
  41. package/dist/highlight/core/index.js +69 -0
  42. package/dist/highlight/index.d.ts +34 -2
  43. package/dist/highlight/index.js +57 -2
  44. package/dist/i18n/index.d.ts +39 -1
  45. package/dist/i18n/index.js +1 -2
  46. package/dist/i18n/middleware.d.ts +2 -3
  47. package/dist/i18n/middleware.js +1 -2
  48. package/dist/{icon-BWwSDabM.js → icon-OtPFhyk1.js} +1 -2
  49. package/dist/link.d.ts +3 -4
  50. package/dist/link.js +1 -2
  51. package/dist/{mdast-utils-mc9-X-PK.js → mdast-utils-gJMY143g.js} +1 -2
  52. package/dist/mdx-plugins/codeblock-utils.d.ts +35 -1
  53. package/dist/mdx-plugins/codeblock-utils.js +1 -2
  54. package/dist/mdx-plugins/index.d.ts +18 -15
  55. package/dist/mdx-plugins/index.js +7 -5
  56. package/dist/mdx-plugins/rehype-code.core.d.ts +38 -0
  57. package/dist/mdx-plugins/rehype-code.core.js +104 -0
  58. package/dist/mdx-plugins/rehype-code.d.ts +18 -2
  59. package/dist/mdx-plugins/rehype-code.js +24 -3
  60. package/dist/mdx-plugins/rehype-toc.d.ts +16 -1
  61. package/dist/mdx-plugins/rehype-toc.js +127 -1
  62. package/dist/mdx-plugins/remark-admonition.d.ts +20 -1
  63. package/dist/mdx-plugins/remark-admonition.js +2 -3
  64. package/dist/mdx-plugins/remark-code-tab.d.ts +30 -1
  65. package/dist/mdx-plugins/remark-code-tab.js +4 -5
  66. package/dist/mdx-plugins/remark-directive-admonition.d.ts +34 -1
  67. package/dist/mdx-plugins/remark-directive-admonition.js +1 -2
  68. package/dist/mdx-plugins/remark-feedback-block.d.ts +51 -0
  69. package/dist/mdx-plugins/remark-feedback-block.js +47 -0
  70. package/dist/mdx-plugins/remark-gfm.d.ts +2 -2
  71. package/dist/mdx-plugins/remark-heading.d.ts +35 -1
  72. package/dist/mdx-plugins/remark-heading.js +2 -3
  73. package/dist/mdx-plugins/remark-image.d.ts +63 -1
  74. package/dist/mdx-plugins/remark-image.js +1 -2
  75. package/dist/mdx-plugins/remark-mdx-files.d.ts +55 -2
  76. package/dist/mdx-plugins/remark-mdx-files.js +103 -13
  77. package/dist/mdx-plugins/remark-mdx-mermaid.d.ts +15 -1
  78. package/dist/mdx-plugins/remark-mdx-mermaid.js +1 -2
  79. package/dist/mdx-plugins/remark-npm.d.ts +34 -1
  80. package/dist/mdx-plugins/remark-npm.js +1 -2
  81. package/dist/mdx-plugins/remark-steps.d.ts +26 -1
  82. package/dist/mdx-plugins/remark-steps.js +1 -2
  83. package/dist/mdx-plugins/remark-structure.d.ts +75 -1
  84. package/dist/mdx-plugins/remark-structure.js +7 -8
  85. package/dist/{mixedbread-DlByNYSd.js → mixedbread-Bx9drx9S.js} +6 -5
  86. package/dist/negotiation/index.d.ts +1 -2
  87. package/dist/negotiation/index.js +1 -2
  88. package/dist/{normalize-url-ChLsV26G.js → normalize-url-DUHbcuVM.js} +1 -2
  89. package/dist/{orama-cloud-DH3g37zc.js → orama-cloud-ByznDyOk.js} +6 -7
  90. package/dist/orama-cloud-legacy-BbgJnf5f.js +81 -0
  91. package/dist/page-tree/index.d.ts +3 -45
  92. package/dist/page-tree/index.js +1 -1
  93. package/dist/{index-2U6Tl4--.d.ts → path-B77y3W0_.d.ts} +111 -98
  94. package/dist/{path-DHIjrDBP.js → path-D0Bwm6Fs.js} +2 -3
  95. package/dist/{remove-undefined-Cfs4o_mM.js → remove-undefined-CJm9cyrC.js} +1 -2
  96. package/dist/search/algolia.d.ts +66 -2
  97. package/dist/search/algolia.js +1 -2
  98. package/dist/search/client.d.ts +30 -7
  99. package/dist/search/client.js +27 -22
  100. package/dist/search/index.d.ts +1 -2
  101. package/dist/search/index.js +41 -1
  102. package/dist/search/orama-cloud-legacy.d.ts +77 -0
  103. package/dist/search/orama-cloud-legacy.js +49 -0
  104. package/dist/search/orama-cloud.d.ts +5 -9
  105. package/dist/search/orama-cloud.js +1 -2
  106. package/dist/search/server.d.ts +87 -4
  107. package/dist/search/server.js +7 -8
  108. package/dist/source/client/index.d.ts +13 -11
  109. package/dist/source/client/index.js +22 -13
  110. package/dist/source/index.d.ts +5 -3
  111. package/dist/source/index.js +428 -333
  112. package/dist/source/plugins/lucide-icons.d.ts +5 -4
  113. package/dist/source/plugins/lucide-icons.js +2 -3
  114. package/dist/source/plugins/slugs.d.ts +24 -2
  115. package/dist/source/plugins/slugs.js +2 -3
  116. package/dist/source/plugins/status-badges.d.ts +52 -0
  117. package/dist/source/plugins/status-badges.js +54 -0
  118. package/dist/source/schema.d.ts +1 -3
  119. package/dist/source/schema.js +1 -2
  120. package/dist/{static-Dq8pA8Ay.js → static-DTxK4eHk.js} +5 -6
  121. package/dist/toc.d.ts +1 -2
  122. package/dist/toc.js +1 -2
  123. package/dist/{rehype-code-sM9Tq-r7.js → transformer-icon-BYedaeE8.js} +1 -96
  124. package/dist/transformer-icon-D7-6aFzt.d.ts +18 -0
  125. package/dist/types-BSnJn7kF.d.ts +6 -0
  126. package/dist/{util-CK2ykiif.d.ts → util-C60LmklF.d.ts} +1 -2
  127. package/dist/{util-s9piKHsk.js → util-De0ALHOx.js} +1 -2
  128. package/dist/utils/use-media-query.d.ts +1 -2
  129. package/dist/utils/use-media-query.js +1 -2
  130. package/dist/utils/use-on-change.d.ts +1 -2
  131. package/dist/utils/use-on-change.js +1 -2
  132. package/dist/{utils-DUvi2WkD.js → utils-Bc53B3CJ.js} +8 -7
  133. package/dist/utils-IgHyYnrz.d.ts +45 -0
  134. package/package.json +68 -38
  135. package/dist/advanced-BRT5Ij43.js.map +0 -1
  136. package/dist/algolia-CQPXCnjV.js.map +0 -1
  137. package/dist/algolia-Cc1y6qWl.d.ts +0 -68
  138. package/dist/algolia-Cc1y6qWl.d.ts.map +0 -1
  139. package/dist/breadcrumb.d.ts.map +0 -1
  140. package/dist/breadcrumb.js.map +0 -1
  141. package/dist/codeblock-utils-DDnYb8gi.d.ts +0 -37
  142. package/dist/codeblock-utils-DDnYb8gi.d.ts.map +0 -1
  143. package/dist/content/github.d.ts.map +0 -1
  144. package/dist/content/github.js.map +0 -1
  145. package/dist/content/index.d.ts.map +0 -1
  146. package/dist/content/index.js.map +0 -1
  147. package/dist/content/mdx/preset-bundler.d.ts.map +0 -1
  148. package/dist/content/mdx/preset-bundler.js.map +0 -1
  149. package/dist/content/mdx/preset-runtime.d.ts.map +0 -1
  150. package/dist/content/mdx/preset-runtime.js.map +0 -1
  151. package/dist/content/toc.d.ts.map +0 -1
  152. package/dist/content/toc.js.map +0 -1
  153. package/dist/definitions-DuxDer_c.d.ts.map +0 -1
  154. package/dist/dynamic-link.d.ts.map +0 -1
  155. package/dist/dynamic-link.js.map +0 -1
  156. package/dist/fetch-B5e9CFfN.js.map +0 -1
  157. package/dist/framework/index.d.ts.map +0 -1
  158. package/dist/framework/index.js.map +0 -1
  159. package/dist/framework/next.d.ts.map +0 -1
  160. package/dist/framework/next.js.map +0 -1
  161. package/dist/framework/react-router.d.ts.map +0 -1
  162. package/dist/framework/react-router.js.map +0 -1
  163. package/dist/framework/tanstack.d.ts.map +0 -1
  164. package/dist/framework/tanstack.js.map +0 -1
  165. package/dist/framework/waku.d.ts.map +0 -1
  166. package/dist/framework/waku.js.map +0 -1
  167. package/dist/highlight/client.d.ts.map +0 -1
  168. package/dist/highlight/client.js.map +0 -1
  169. package/dist/i18n/index.js.map +0 -1
  170. package/dist/i18n/middleware.d.ts.map +0 -1
  171. package/dist/i18n/middleware.js.map +0 -1
  172. package/dist/icon-BWwSDabM.js.map +0 -1
  173. package/dist/index-2U6Tl4--.d.ts.map +0 -1
  174. package/dist/index-Bw-DCOra.d.ts +0 -41
  175. package/dist/index-Bw-DCOra.d.ts.map +0 -1
  176. package/dist/link.d.ts.map +0 -1
  177. package/dist/link.js.map +0 -1
  178. package/dist/mdast-utils-mc9-X-PK.js.map +0 -1
  179. package/dist/mdx-plugins/codeblock-utils.js.map +0 -1
  180. package/dist/mdx-plugins/remark-admonition.js.map +0 -1
  181. package/dist/mdx-plugins/remark-code-tab.js.map +0 -1
  182. package/dist/mdx-plugins/remark-directive-admonition.js.map +0 -1
  183. package/dist/mdx-plugins/remark-heading.js.map +0 -1
  184. package/dist/mdx-plugins/remark-image.js.map +0 -1
  185. package/dist/mdx-plugins/remark-mdx-files.js.map +0 -1
  186. package/dist/mdx-plugins/remark-mdx-mermaid.js.map +0 -1
  187. package/dist/mdx-plugins/remark-npm.js.map +0 -1
  188. package/dist/mdx-plugins/remark-steps.js.map +0 -1
  189. package/dist/mdx-plugins/remark-structure.js.map +0 -1
  190. package/dist/mixedbread-DlByNYSd.js.map +0 -1
  191. package/dist/negotiation/index.d.ts.map +0 -1
  192. package/dist/negotiation/index.js.map +0 -1
  193. package/dist/normalize-url-ChLsV26G.js.map +0 -1
  194. package/dist/orama-cloud-DH3g37zc.js.map +0 -1
  195. package/dist/page-tree/index.d.ts.map +0 -1
  196. package/dist/path-DHIjrDBP.js.map +0 -1
  197. package/dist/rehype-code-sM9Tq-r7.js.map +0 -1
  198. package/dist/rehype-code-vVWG4-ej.d.ts +0 -58
  199. package/dist/rehype-code-vVWG4-ej.d.ts.map +0 -1
  200. package/dist/rehype-toc-DJvSyE0o.d.ts +0 -18
  201. package/dist/rehype-toc-DJvSyE0o.d.ts.map +0 -1
  202. package/dist/rehype-toc-DVwJcwvA.js +0 -143
  203. package/dist/rehype-toc-DVwJcwvA.js.map +0 -1
  204. package/dist/remark-admonition-DOwBWzsH.d.ts +0 -22
  205. package/dist/remark-admonition-DOwBWzsH.d.ts.map +0 -1
  206. package/dist/remark-code-tab-CXsYlims.d.ts +0 -32
  207. package/dist/remark-code-tab-CXsYlims.d.ts.map +0 -1
  208. package/dist/remark-directive-admonition-BCm_yiU9.d.ts +0 -36
  209. package/dist/remark-directive-admonition-BCm_yiU9.d.ts.map +0 -1
  210. package/dist/remark-gfm-CeWpMwyk.d.ts +0 -2
  211. package/dist/remark-heading-CXvCY0go.d.ts +0 -37
  212. package/dist/remark-heading-CXvCY0go.d.ts.map +0 -1
  213. package/dist/remark-image-CvUis4R1.d.ts +0 -65
  214. package/dist/remark-image-CvUis4R1.d.ts.map +0 -1
  215. package/dist/remark-mdx-files-DOYafA4x.d.ts +0 -42
  216. package/dist/remark-mdx-files-DOYafA4x.d.ts.map +0 -1
  217. package/dist/remark-mdx-mermaid-BdSUUiCG.d.ts +0 -17
  218. package/dist/remark-mdx-mermaid-BdSUUiCG.d.ts.map +0 -1
  219. package/dist/remark-npm-Bo08HqcQ.d.ts +0 -36
  220. package/dist/remark-npm-Bo08HqcQ.d.ts.map +0 -1
  221. package/dist/remark-steps-CHJN-rtm.d.ts +0 -28
  222. package/dist/remark-steps-CHJN-rtm.d.ts.map +0 -1
  223. package/dist/remark-structure-DGuWR82i.d.ts +0 -77
  224. package/dist/remark-structure-DGuWR82i.d.ts.map +0 -1
  225. package/dist/remove-undefined-Cfs4o_mM.js.map +0 -1
  226. package/dist/search/algolia.js.map +0 -1
  227. package/dist/search/client.d.ts.map +0 -1
  228. package/dist/search/client.js.map +0 -1
  229. package/dist/search/index.d.ts.map +0 -1
  230. package/dist/search/orama-cloud.d.ts.map +0 -1
  231. package/dist/search/orama-cloud.js.map +0 -1
  232. package/dist/search/server.js.map +0 -1
  233. package/dist/search-D6ChCLhY.js +0 -44
  234. package/dist/search-D6ChCLhY.js.map +0 -1
  235. package/dist/server-DmY4lGBs.d.ts +0 -133
  236. package/dist/server-DmY4lGBs.d.ts.map +0 -1
  237. package/dist/shiki-B5wNmyIZ.js +0 -80
  238. package/dist/shiki-B5wNmyIZ.js.map +0 -1
  239. package/dist/shiki-Dq3XIYAT.d.ts +0 -33
  240. package/dist/shiki-Dq3XIYAT.d.ts.map +0 -1
  241. package/dist/source/client/index.d.ts.map +0 -1
  242. package/dist/source/client/index.js.map +0 -1
  243. package/dist/source/index.js.map +0 -1
  244. package/dist/source/plugins/lucide-icons.d.ts.map +0 -1
  245. package/dist/source/plugins/lucide-icons.js.map +0 -1
  246. package/dist/source/plugins/slugs.js.map +0 -1
  247. package/dist/source/schema.d.ts.map +0 -1
  248. package/dist/source/schema.js.map +0 -1
  249. package/dist/static-Dq8pA8Ay.js.map +0 -1
  250. package/dist/toc.d.ts.map +0 -1
  251. package/dist/toc.js.map +0 -1
  252. package/dist/util-CK2ykiif.d.ts.map +0 -1
  253. package/dist/util-s9piKHsk.js.map +0 -1
  254. package/dist/utils/use-effect-event.d.ts +0 -11
  255. package/dist/utils/use-effect-event.d.ts.map +0 -1
  256. package/dist/utils/use-effect-event.js +0 -19
  257. package/dist/utils/use-effect-event.js.map +0 -1
  258. package/dist/utils/use-media-query.d.ts.map +0 -1
  259. package/dist/utils/use-media-query.js.map +0 -1
  260. package/dist/utils/use-on-change.d.ts.map +0 -1
  261. package/dist/utils/use-on-change.js.map +0 -1
  262. package/dist/utils-DUvi2WkD.js.map +0 -1
@@ -1,14 +1,14 @@
1
- import { t as normalizeUrl } from "../normalize-url-ChLsV26G.js";
2
- import { c as visit } from "../utils-DUvi2WkD.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-DHIjrDBP.js";
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-BWwSDabM.js";
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$1] of Object.entries(sources)) for (const file of source$1.files) out.files.push({
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$1) {
26
+ function update(source) {
27
27
  return {
28
28
  files(fn) {
29
- source$1.files = fn(source$1.files);
29
+ source.files = fn(source.files);
30
30
  return this;
31
31
  },
32
32
  page(fn) {
33
- for (let i = 0; i < source$1.files.length; i++) {
34
- const file = source$1.files[i];
35
- if (file.type === "page") source$1.files[i] = fn(file);
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$1.files.length; i++) {
41
- const file = source$1.files[i];
42
- if (file.type === "meta") source$1.files[i] = fn(file);
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$1;
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$1) {
67
- return this.files.get(path$1);
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$1) {
73
- return this.folders.get(path$1);
72
+ readDir(path) {
73
+ return this.folders.get(path);
74
74
  }
75
- write(path$1, file) {
76
- if (!this.files.has(path$1)) {
77
- const dir = dirname(path$1);
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$1);
79
+ this.readDir(dir)?.push(path);
80
80
  }
81
- this.files.set(path$1, file);
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$1, recursive = false) {
90
- if (this.files.delete(path$1)) return true;
89
+ delete(path, recursive = false) {
90
+ if (this.files.delete(path)) return true;
91
91
  if (recursive) {
92
- const folder = this.folders.get(path$1);
92
+ const folder = this.folders.get(path);
93
93
  if (!folder) return false;
94
- this.folders.delete(path$1);
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$1) {
104
- const segments = splitPath(path$1);
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$1) {
121
- const [locale, ...segs] = path$1.split("/");
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$1];
123
+ return [path];
124
124
  },
125
- dot(path$1) {
126
- const dir = dirname(path$1);
127
- const parts = basename(path$1).split(".");
128
- if (parts.length < 3) return [path$1];
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$1];
130
+ if (!isLocaleValid(locale)) return [path];
131
131
  return [joinPath(dir, parts.join(".")), locale];
132
132
  },
133
- none(path$1) {
134
- return [path$1];
133
+ none(path) {
134
+ return [path];
135
135
  }
136
136
  };
137
+ const EmptyLang = Symbol();
137
138
  /**
138
- * @param defaultLanguage - language to use when i18n is not configured.
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 buildContentStorage(loaderConfig, defaultLanguage) {
144
- const { source: source$1, plugins = [], i18n = {
145
- defaultLanguage,
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$1.files) {
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
- const fallbackLang = i18n.fallbackLanguage !== null ? i18n.fallbackLanguage ?? i18n.defaultLanguage : null;
176
- function scan(lang) {
177
- if (storages[lang]) return;
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
- storages[lang] = storage;
175
+ return storage;
187
176
  }
188
- for (const lang of i18n.languages) scan(lang);
189
- return storages;
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$1) {
197
- const segments = splitPath(slash(path$1));
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
- const content = this.storage.read(file);
212
- if (content) isolatedStorage.write(file, content);
219
+ isolatedStorage.write(file, this.storage.read(file));
213
220
  }
214
- if (isolatedStorage.getFiles().length === 0) return root;
215
- root.fallback = this.builder.build(isolatedStorage, {
216
- ...this.options,
217
- id: `fallback-${root.$id ?? ""}`,
218
- generateFallback: false
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
- function createPageTreeBuilder(loaderConfig) {
244
- const { plugins = [], url, pageTree: defaultOptions = {} } = loaderConfig;
245
- return {
246
- build(storage, options = defaultOptions) {
247
- const key = "";
248
- return this.buildI18n({ [key]: storage }, options)[key];
249
- },
250
- buildI18n(storages, options = defaultOptions) {
251
- let nextId = 0;
252
- const out = {};
253
- const transformers = [];
254
- if (options.transformers) transformers.push(...options.transformers);
255
- for (const plugin of plugins) if (plugin.transformPageTree) transformers.push(plugin.transformPageTree);
256
- if (options.generateFallback ?? true) transformers.push(transformerFallback());
257
- for (const [locale, storage] of Object.entries(storages)) {
258
- let rootId = locale.length === 0 ? "root" : locale;
259
- if (options.id) rootId = `${options.id}-${rootId}`;
260
- out[locale] = createPageTreeBuilderUtils({
261
- rootId,
262
- transformers,
263
- builder: this,
264
- options,
265
- getUrl: url,
266
- locale,
267
- storage,
268
- storages,
269
- generateNodeId() {
270
- return "_" + nextId++;
271
- }
272
- }).root();
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
- return (name, format) => {
287
- return map.get(name + "." + format) ?? name;
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
- return {
297
- buildPaths(paths, reversed = false) {
298
- const items = [];
299
- const folders = [];
300
- const sortedPaths = paths.sort((a, b) => a.localeCompare(b) * (reversed ? -1 : 1));
301
- for (const path$1 of sortedPaths) {
302
- const fileNode = this.file(path$1);
303
- if (fileNode) {
304
- if (basename(path$1, extname(path$1)) === "index") items.unshift(fileNode);
305
- else items.push(fileNode);
306
- continue;
307
- }
308
- const dirNode = this.folder(path$1, false);
309
- if (dirNode) folders.push(dirNode);
310
- }
311
- items.push(...folders);
312
- return items;
313
- },
314
- resolveFolderItem(folderPath, item) {
315
- if (item === rest || item === restReversed) return item;
316
- let match = separator.exec(item);
317
- if (match?.groups) {
318
- let node = {
319
- $id: nextNodeId(),
320
- type: "separator",
321
- icon: match.groups.icon,
322
- name: match.groups.name
323
- };
324
- for (const transformer of ctx.transformers) {
325
- if (!transformer.separator) continue;
326
- node = transformer.separator.call(ctx, node);
327
- }
328
- return [node];
329
- }
330
- match = link.exec(item);
331
- if (match?.groups) {
332
- const { icon, url, name, external } = match.groups;
333
- let node = {
334
- $id: nextNodeId(),
335
- type: "page",
336
- icon,
337
- name,
338
- url,
339
- external: external ? true : void 0
340
- };
341
- for (const transformer of ctx.transformers) {
342
- if (!transformer.file) continue;
343
- node = transformer.file.call(ctx, node);
344
- }
345
- return [node];
346
- }
347
- const isExcept = item.startsWith(excludePrefix);
348
- const isExtract = !isExcept && item.startsWith(extractPrefix);
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
- type: "folder",
391
- name: metadata.title ?? index?.name ?? (() => {
392
- const folderName = basename(folderPath);
393
- return pathToName(group.exec(folderName)?.[1] ?? folderName);
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
- visitedPaths.add(folderPath);
406
- for (const transformer of transformers) {
407
- if (!transformer.folder) continue;
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
- return node;
411
- },
412
- file(path$1) {
413
- const { options, getUrl, storage, locale, transformers } = ctx;
414
- const page = storage.read(path$1);
415
- if (page?.format !== "page") return;
416
- const { title, description, icon } = page.data;
417
- let item = {
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
- url: getUrl(page.slugs, locale),
424
- $ref: !options.noRef ? { file: path$1 } : void 0
379
+ name,
380
+ url
425
381
  };
426
- visitedPaths.add(path$1);
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
- item = transformer.file.call(ctx, item, path$1);
385
+ node = transformer.file.call(this.ctx, node);
430
386
  }
431
- return item;
432
- },
433
- root() {
434
- const folder = this.folder("", true);
435
- let root = {
436
- $id: ctx.rootId,
437
- name: folder.name || "Docs",
438
- children: folder.children
439
- };
440
- for (const transformer of ctx.transformers) {
441
- if (!transformer.root) continue;
442
- root = transformer.root.call(ctx, root);
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
- return root;
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 indexPages(storages, { url }) {
464
- const result = {
465
- pages: /* @__PURE__ */ new Map(),
466
- pathToMeta: /* @__PURE__ */ new Map(),
467
- pathToPage: /* @__PURE__ */ new Map()
468
- };
469
- for (const [lang, storage] of Object.entries(storages)) for (const filePath of storage.getFiles()) {
470
- const item = storage.read(filePath);
471
- const path$1 = `${lang}.${filePath}`;
472
- if (item.format === "meta") {
473
- result.pathToMeta.set(path$1, {
474
- path: item.path,
475
- absolutePath: item.absolutePath,
476
- data: item.data
477
- });
478
- continue;
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
- const page = {
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 defaultLanguage = i18n?.defaultLanguage ?? "";
509
- const storages = buildContentStorage(loaderConfig, defaultLanguage);
510
- const walker = indexPages(storages, loaderConfig);
511
- const builder = createPageTreeBuilder(loaderConfig);
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
- return pageTrees ??= builder.buildI18n(storages);
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
- const trees = getPageTrees();
520
- return i18n ? trees : trees[defaultLanguage];
618
+ return getPageTrees();
521
619
  },
522
620
  set pageTree(v) {
523
- if (i18n) pageTrees = v;
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$1 = joinPath(dir, value);
534
- target = walker.pathToPage.get(`${language}.${path$1}`);
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
- const pages = [];
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
- let page = walker.pages.get(`${language}.${slugs.join("/")}`);
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 walker.pathToMeta.get(`${language}.${ref}`);
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 walker.pathToPage.get(`${language}.${ref}`);
668
+ return indexer.getPage(ref, language);
580
669
  },
581
- getPageTree(locale = defaultLanguage) {
582
- const trees = getPageTrees();
583
- return trees[locale] ?? trees[defaultLanguage];
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 visit(tree, (node) => {
595
- node = { ...node };
596
- if ("icon" in node && node.icon) node.icon = renderToString(node.icon);
597
- if (node.name) node.name = renderToString(node.name);
598
- if ("children" in node) node.children = [...node.children];
599
- return node;
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$1, { slugs, icon, plugins = [], baseUrl, url, ...base }) {
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: source$1,
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 };