fumadocs-core 16.4.1 → 16.4.2

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 (278) hide show
  1. package/dist/advanced-BRT5Ij43.js +80 -0
  2. package/dist/advanced-BRT5Ij43.js.map +1 -0
  3. package/dist/algolia-CBBN8R6-.d.ts +68 -0
  4. package/dist/algolia-CBBN8R6-.d.ts.map +1 -0
  5. package/dist/algolia-CQPXCnjV.js +49 -0
  6. package/dist/algolia-CQPXCnjV.js.map +1 -0
  7. package/dist/breadcrumb.d.ts +29 -27
  8. package/dist/breadcrumb.d.ts.map +1 -0
  9. package/dist/breadcrumb.js +55 -72
  10. package/dist/breadcrumb.js.map +1 -0
  11. package/dist/chunk-B-ezknvj.js +42 -0
  12. package/dist/codeblock-utils-lld8UiQo.d.ts +37 -0
  13. package/dist/codeblock-utils-lld8UiQo.d.ts.map +1 -0
  14. package/dist/content/github.d.ts +43 -32
  15. package/dist/content/github.d.ts.map +1 -0
  16. package/dist/content/github.js +29 -43
  17. package/dist/content/github.js.map +1 -0
  18. package/dist/content/index.d.ts +20 -13
  19. package/dist/content/index.d.ts.map +1 -0
  20. package/dist/content/index.js +17 -23
  21. package/dist/content/index.js.map +1 -0
  22. package/dist/content/mdx/preset-bundler.d.ts +22 -24
  23. package/dist/content/mdx/preset-bundler.d.ts.map +1 -0
  24. package/dist/content/mdx/preset-bundler.js +38 -69
  25. package/dist/content/mdx/preset-bundler.js.map +1 -0
  26. package/dist/content/mdx/preset-runtime.d.ts +22 -24
  27. package/dist/content/mdx/preset-runtime.d.ts.map +1 -0
  28. package/dist/content/mdx/preset-runtime.js +36 -68
  29. package/dist/content/mdx/preset-runtime.js.map +1 -0
  30. package/dist/content/toc.d.ts +7 -6
  31. package/dist/content/toc.d.ts.map +1 -0
  32. package/dist/content/toc.js +15 -19
  33. package/dist/content/toc.js.map +1 -0
  34. package/dist/definitions-DuxDer_c.d.ts +62 -0
  35. package/dist/definitions-DuxDer_c.d.ts.map +1 -0
  36. package/dist/dynamic-link.d.ts +7 -5
  37. package/dist/dynamic-link.d.ts.map +1 -0
  38. package/dist/dynamic-link.js +29 -27
  39. package/dist/dynamic-link.js.map +1 -0
  40. package/dist/fetch-B5e9CFfN.js +20 -0
  41. package/dist/fetch-B5e9CFfN.js.map +1 -0
  42. package/dist/framework/index.d.ts +38 -29
  43. package/dist/framework/index.d.ts.map +1 -0
  44. package/dist/framework/index.js +68 -17
  45. package/dist/framework/index.js.map +1 -0
  46. package/dist/framework/next.d.ts +15 -10
  47. package/dist/framework/next.d.ts.map +1 -0
  48. package/dist/framework/next.js +18 -26
  49. package/dist/framework/next.js.map +1 -0
  50. package/dist/framework/react-router.d.ts +15 -10
  51. package/dist/framework/react-router.d.ts.map +1 -0
  52. package/dist/framework/react-router.js +42 -55
  53. package/dist/framework/react-router.js.map +1 -0
  54. package/dist/framework/tanstack.d.ts +15 -10
  55. package/dist/framework/tanstack.d.ts.map +1 -0
  56. package/dist/framework/tanstack.js +54 -69
  57. package/dist/framework/tanstack.js.map +1 -0
  58. package/dist/framework/waku.d.ts +15 -10
  59. package/dist/framework/waku.d.ts.map +1 -0
  60. package/dist/framework/waku.js +47 -58
  61. package/dist/framework/waku.js.map +1 -0
  62. package/dist/highlight/client.d.ts +6 -7
  63. package/dist/highlight/client.d.ts.map +1 -0
  64. package/dist/highlight/client.js +22 -14
  65. package/dist/highlight/client.js.map +1 -0
  66. package/dist/highlight/index.d.ts +2 -30
  67. package/dist/highlight/index.js +3 -13
  68. package/dist/i18n/index.d.ts +2 -39
  69. package/dist/i18n/index.js +6 -7
  70. package/dist/i18n/index.js.map +1 -0
  71. package/dist/i18n/middleware.d.ts +36 -28
  72. package/dist/i18n/middleware.d.ts.map +1 -0
  73. package/dist/i18n/middleware.js +55 -73
  74. package/dist/i18n/middleware.js.map +1 -0
  75. package/dist/icon-Dt7IObrc.js +19 -0
  76. package/dist/icon-Dt7IObrc.js.map +1 -0
  77. package/dist/index-2U6Tl4--.d.ts +379 -0
  78. package/dist/index-2U6Tl4--.d.ts.map +1 -0
  79. package/dist/index-Bw-DCOra.d.ts +41 -0
  80. package/dist/index-Bw-DCOra.d.ts.map +1 -0
  81. package/dist/link.d.ts +17 -15
  82. package/dist/link.d.ts.map +1 -0
  83. package/dist/link.js +29 -9
  84. package/dist/link.js.map +1 -0
  85. package/dist/mdast-utils-mc9-X-PK.js +40 -0
  86. package/dist/mdast-utils-mc9-X-PK.js.map +1 -0
  87. package/dist/mdx-plugins/codeblock-utils.d.ts +2 -29
  88. package/dist/mdx-plugins/codeblock-utils.js +71 -9
  89. package/dist/mdx-plugins/codeblock-utils.js.map +1 -0
  90. package/dist/mdx-plugins/index.d.ts +15 -20
  91. package/dist/mdx-plugins/index.js +18 -73
  92. package/dist/mdx-plugins/rehype-code.d.ts +2 -55
  93. package/dist/mdx-plugins/rehype-code.js +5 -15
  94. package/dist/mdx-plugins/rehype-toc.d.ts +2 -14
  95. package/dist/mdx-plugins/rehype-toc.js +3 -7
  96. package/dist/mdx-plugins/remark-admonition.d.ts +2 -20
  97. package/dist/mdx-plugins/remark-admonition.js +74 -8
  98. package/dist/mdx-plugins/remark-admonition.js.map +1 -0
  99. package/dist/mdx-plugins/remark-code-tab.d.ts +2 -30
  100. package/dist/mdx-plugins/remark-code-tab.js +183 -7
  101. package/dist/mdx-plugins/remark-code-tab.js.map +1 -0
  102. package/dist/mdx-plugins/remark-directive-admonition.d.ts +2 -27
  103. package/dist/mdx-plugins/remark-directive-admonition.js +60 -7
  104. package/dist/mdx-plugins/remark-directive-admonition.js.map +1 -0
  105. package/dist/mdx-plugins/remark-gfm.d.ts +2 -1
  106. package/dist/mdx-plugins/remark-gfm.js +3 -7
  107. package/dist/mdx-plugins/remark-heading.d.ts +2 -31
  108. package/dist/mdx-plugins/remark-heading.js +45 -8
  109. package/dist/mdx-plugins/remark-heading.js.map +1 -0
  110. package/dist/mdx-plugins/remark-image.d.ts +2 -57
  111. package/dist/mdx-plugins/remark-image.js +192 -7
  112. package/dist/mdx-plugins/remark-image.js.map +1 -0
  113. package/dist/mdx-plugins/remark-mdx-files.d.ts +2 -40
  114. package/dist/mdx-plugins/remark-mdx-files.js +187 -7
  115. package/dist/mdx-plugins/remark-mdx-files.js.map +1 -0
  116. package/dist/mdx-plugins/remark-mdx-mermaid.d.ts +2 -15
  117. package/dist/mdx-plugins/remark-mdx-mermaid.js +31 -7
  118. package/dist/mdx-plugins/remark-mdx-mermaid.js.map +1 -0
  119. package/dist/mdx-plugins/remark-npm.d.ts +2 -31
  120. package/dist/mdx-plugins/remark-npm.js +68 -8
  121. package/dist/mdx-plugins/remark-npm.js.map +1 -0
  122. package/dist/mdx-plugins/remark-steps.d.ts +2 -23
  123. package/dist/mdx-plugins/remark-steps.js +77 -7
  124. package/dist/mdx-plugins/remark-steps.js.map +1 -0
  125. package/dist/mdx-plugins/remark-structure.d.ts +2 -71
  126. package/dist/mdx-plugins/remark-structure.js +105 -11
  127. package/dist/mdx-plugins/remark-structure.js.map +1 -0
  128. package/dist/mixedbread-DlByNYSd.js +88 -0
  129. package/dist/mixedbread-DlByNYSd.js.map +1 -0
  130. package/dist/negotiation/index.d.ts +6 -4
  131. package/dist/negotiation/index.d.ts.map +1 -0
  132. package/dist/negotiation/index.js +41 -11
  133. package/dist/negotiation/index.js.map +1 -0
  134. package/dist/normalize-url-DP9-1I-S.js +16 -0
  135. package/dist/normalize-url-DP9-1I-S.js.map +1 -0
  136. package/dist/orama-cloud-DH3g37zc.js +84 -0
  137. package/dist/orama-cloud-DH3g37zc.js.map +1 -0
  138. package/dist/page-tree/index.d.ts +23 -11
  139. package/dist/page-tree/index.d.ts.map +1 -0
  140. package/dist/page-tree/index.js +3 -17
  141. package/dist/path-DHIjrDBP.js +60 -0
  142. package/dist/path-DHIjrDBP.js.map +1 -0
  143. package/dist/rehype-code-CdiZ1Y6P.js +241 -0
  144. package/dist/rehype-code-CdiZ1Y6P.js.map +1 -0
  145. package/dist/rehype-code-vVWG4-ej.d.ts +58 -0
  146. package/dist/rehype-code-vVWG4-ej.d.ts.map +1 -0
  147. package/dist/rehype-toc-DJvSyE0o.d.ts +18 -0
  148. package/dist/rehype-toc-DJvSyE0o.d.ts.map +1 -0
  149. package/dist/rehype-toc-DVwJcwvA.js +143 -0
  150. package/dist/rehype-toc-DVwJcwvA.js.map +1 -0
  151. package/dist/remark-admonition-DOwBWzsH.d.ts +22 -0
  152. package/dist/remark-admonition-DOwBWzsH.d.ts.map +1 -0
  153. package/dist/remark-code-tab-CXsYlims.d.ts +32 -0
  154. package/dist/remark-code-tab-CXsYlims.d.ts.map +1 -0
  155. package/dist/remark-directive-admonition-BCm_yiU9.d.ts +36 -0
  156. package/dist/remark-directive-admonition-BCm_yiU9.d.ts.map +1 -0
  157. package/dist/remark-gfm-CeWpMwyk.d.ts +2 -0
  158. package/dist/remark-heading-CXvCY0go.d.ts +37 -0
  159. package/dist/remark-heading-CXvCY0go.d.ts.map +1 -0
  160. package/dist/remark-image-CvUis4R1.d.ts +65 -0
  161. package/dist/remark-image-CvUis4R1.d.ts.map +1 -0
  162. package/dist/remark-mdx-files-B31xFFG4.d.ts +56 -0
  163. package/dist/remark-mdx-files-B31xFFG4.d.ts.map +1 -0
  164. package/dist/remark-mdx-mermaid-BdSUUiCG.d.ts +17 -0
  165. package/dist/remark-mdx-mermaid-BdSUUiCG.d.ts.map +1 -0
  166. package/dist/remark-npm-BIvIEKT2.d.ts +36 -0
  167. package/dist/remark-npm-BIvIEKT2.d.ts.map +1 -0
  168. package/dist/remark-steps-CHJN-rtm.d.ts +28 -0
  169. package/dist/remark-steps-CHJN-rtm.d.ts.map +1 -0
  170. package/dist/remark-structure-RZD2gGKp.d.ts +77 -0
  171. package/dist/remark-structure-RZD2gGKp.d.ts.map +1 -0
  172. package/dist/remove-undefined-Cfs4o_mM.js +19 -0
  173. package/dist/remove-undefined-Cfs4o_mM.js.map +1 -0
  174. package/dist/search/algolia.d.ts +3 -69
  175. package/dist/search/algolia.js +69 -63
  176. package/dist/search/algolia.js.map +1 -0
  177. package/dist/search/client.d.ts +120 -114
  178. package/dist/search/client.d.ts.map +1 -0
  179. package/dist/search/client.js +92 -91
  180. package/dist/search/client.js.map +1 -0
  181. package/dist/search/index.d.ts +20 -18
  182. package/dist/search/index.d.ts.map +1 -0
  183. package/dist/search/index.js +3 -7
  184. package/dist/search/orama-cloud.d.ts +70 -68
  185. package/dist/search/orama-cloud.d.ts.map +1 -0
  186. package/dist/search/orama-cloud.js +46 -54
  187. package/dist/search/orama-cloud.js.map +1 -0
  188. package/dist/search/server.d.ts +6 -136
  189. package/dist/search/server.js +292 -369
  190. package/dist/search/server.js.map +1 -0
  191. package/dist/search-D6ChCLhY.js +44 -0
  192. package/dist/search-D6ChCLhY.js.map +1 -0
  193. package/dist/server-CPR_fgkH.d.ts +133 -0
  194. package/dist/server-CPR_fgkH.d.ts.map +1 -0
  195. package/dist/shiki-4oMYwHED.js +80 -0
  196. package/dist/shiki-4oMYwHED.js.map +1 -0
  197. package/dist/shiki-CIBQys54.d.ts +33 -0
  198. package/dist/shiki-CIBQys54.d.ts.map +1 -0
  199. package/dist/source/client/index.d.ts +7 -5
  200. package/dist/source/client/index.d.ts.map +1 -0
  201. package/dist/source/client/index.js +24 -35
  202. package/dist/source/client/index.js.map +1 -0
  203. package/dist/source/index.d.ts +3 -42
  204. package/dist/source/index.js +599 -752
  205. package/dist/source/index.js.map +1 -0
  206. package/dist/source/plugins/lucide-icons.d.ts +7 -7
  207. package/dist/source/plugins/lucide-icons.d.ts.map +1 -0
  208. package/dist/source/plugins/lucide-icons.js +21 -20
  209. package/dist/source/plugins/lucide-icons.js.map +1 -0
  210. package/dist/source/plugins/slugs.d.ts +3 -0
  211. package/dist/source/plugins/slugs.js +65 -0
  212. package/dist/source/plugins/slugs.js.map +1 -0
  213. package/dist/source/schema.d.ts +17 -14
  214. package/dist/source/schema.d.ts.map +1 -0
  215. package/dist/source/schema.js +26 -22
  216. package/dist/source/schema.js.map +1 -0
  217. package/dist/static-Dq8pA8Ay.js +51 -0
  218. package/dist/static-Dq8pA8Ay.js.map +1 -0
  219. package/dist/toc.d.ts +38 -25
  220. package/dist/toc.d.ts.map +1 -0
  221. package/dist/toc.js +123 -136
  222. package/dist/toc.js.map +1 -0
  223. package/dist/util-CK2ykiif.d.ts +8 -0
  224. package/dist/util-CK2ykiif.d.ts.map +1 -0
  225. package/dist/util-s9piKHsk.js +10 -0
  226. package/dist/util-s9piKHsk.js.map +1 -0
  227. package/dist/utils/use-effect-event.d.ts +3 -1
  228. package/dist/utils/use-effect-event.d.ts.map +1 -0
  229. package/dist/utils/use-effect-event.js +16 -13
  230. package/dist/utils/use-effect-event.js.map +1 -0
  231. package/dist/utils/use-media-query.d.ts +3 -1
  232. package/dist/utils/use-media-query.d.ts.map +1 -0
  233. package/dist/utils/use-media-query.js +20 -20
  234. package/dist/utils/use-media-query.js.map +1 -0
  235. package/dist/utils/use-on-change.d.ts +3 -1
  236. package/dist/utils/use-on-change.d.ts.map +1 -0
  237. package/dist/utils/use-on-change.js +23 -7
  238. package/dist/utils/use-on-change.js.map +1 -0
  239. package/dist/utils-DUvi2WkD.js +134 -0
  240. package/dist/utils-DUvi2WkD.js.map +1 -0
  241. package/package.json +60 -58
  242. package/dist/algolia-IZEDLPHE.js +0 -58
  243. package/dist/chunk-5PMI7QDD.js +0 -220
  244. package/dist/chunk-ADBHPKXG.js +0 -78
  245. package/dist/chunk-APKPSBSB.js +0 -74
  246. package/dist/chunk-CH7YHH7V.js +0 -222
  247. package/dist/chunk-EFVXL2PP.js +0 -144
  248. package/dist/chunk-EMWGTXSW.js +0 -19
  249. package/dist/chunk-FAEPKD7U.js +0 -20
  250. package/dist/chunk-FUUVPEA5.js +0 -29
  251. package/dist/chunk-GINBKBVQ.js +0 -12
  252. package/dist/chunk-GLRQBLGN.js +0 -59
  253. package/dist/chunk-JUF4WZ6G.js +0 -117
  254. package/dist/chunk-K4WNLOVQ.js +0 -75
  255. package/dist/chunk-L4JKQWCM.js +0 -131
  256. package/dist/chunk-MA6O2UUE.js +0 -50
  257. package/dist/chunk-ONG4RVCR.js +0 -8
  258. package/dist/chunk-OTD7MV33.js +0 -53
  259. package/dist/chunk-PFNP6PEB.js +0 -11
  260. package/dist/chunk-SH7BNTG7.js +0 -38
  261. package/dist/chunk-TWIDBWFG.js +0 -84
  262. package/dist/chunk-U67V476Y.js +0 -35
  263. package/dist/chunk-VLSDGCJE.js +0 -47
  264. package/dist/chunk-W6WTLKRA.js +0 -73
  265. package/dist/chunk-X2HFD5QJ.js +0 -275
  266. package/dist/chunk-XJ6ZQNEX.js +0 -91
  267. package/dist/chunk-XN2LKXFZ.js +0 -101
  268. package/dist/chunk-XOFXGHS4.js +0 -93
  269. package/dist/chunk-XZSI7AHE.js +0 -67
  270. package/dist/chunk-YVVDKJ2H.js +0 -34
  271. package/dist/chunk-ZMWYLUDP.js +0 -21
  272. package/dist/definitions-pJ7PybYY.d.ts +0 -60
  273. package/dist/fetch-IBTWQCJR.js +0 -22
  274. package/dist/loader-_E2HOdV0.d.ts +0 -333
  275. package/dist/mixedbread-A3WLENES.js +0 -117
  276. package/dist/orama-cloud-UZAPMPFV.js +0 -93
  277. package/dist/static-A2YJ5TXV.js +0 -62
  278. package/dist/util-bZU2QeJ2.d.ts +0 -6
@@ -1,789 +1,636 @@
1
- import {
2
- iconPlugin
3
- } from "../chunk-FAEPKD7U.js";
4
- import {
5
- basename,
6
- dirname,
7
- extname,
8
- joinPath,
9
- path_exports,
10
- slash,
11
- splitPath
12
- } from "../chunk-XZSI7AHE.js";
13
- import {
14
- normalizeUrl
15
- } from "../chunk-PFNP6PEB.js";
16
- import {
17
- visit
18
- } from "../chunk-L4JKQWCM.js";
19
- import "../chunk-U67V476Y.js";
1
+ import { t as normalizeUrl } from "../normalize-url-DP9-1I-S.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";
4
+ import { getSlugs, slugsPlugin } from "./plugins/slugs.js";
5
+ import { t as iconPlugin } from "../icon-Dt7IObrc.js";
6
+ import path from "node:path";
20
7
 
21
- // src/source/source.ts
8
+ //#region src/source/source.ts
22
9
  function multiple(sources) {
23
- const out = { files: [] };
24
- for (const [type, source2] of Object.entries(sources)) {
25
- for (const file of source2.files) {
26
- out.files.push({
27
- ...file,
28
- data: {
29
- ...file.data,
30
- type
31
- }
32
- });
33
- }
34
- }
35
- return out;
10
+ const out = { files: [] };
11
+ for (const [type, source$1] of Object.entries(sources)) for (const file of source$1.files) out.files.push({
12
+ ...file,
13
+ data: {
14
+ ...file.data,
15
+ type
16
+ }
17
+ });
18
+ return out;
36
19
  }
37
20
  function source(config) {
38
- return {
39
- files: [...config.pages, ...config.metas]
40
- };
21
+ return { files: [...config.pages, ...config.metas] };
41
22
  }
42
- function update(source2) {
43
- return {
44
- files(fn) {
45
- source2.files = fn(source2.files);
46
- return this;
47
- },
48
- page(fn) {
49
- for (let i = 0; i < source2.files.length; i++) {
50
- const file = source2.files[i];
51
- if (file.type === "page") source2.files[i] = fn(file);
52
- }
53
- return this;
54
- },
55
- meta(fn) {
56
- for (let i = 0; i < source2.files.length; i++) {
57
- const file = source2.files[i];
58
- if (file.type === "meta") source2.files[i] = fn(file);
59
- }
60
- return this;
61
- },
62
- build() {
63
- return source2;
64
- }
65
- };
23
+ /**
24
+ * update a source object in-place.
25
+ */
26
+ function update(source$1) {
27
+ return {
28
+ files(fn) {
29
+ source$1.files = fn(source$1.files);
30
+ return this;
31
+ },
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);
36
+ }
37
+ return this;
38
+ },
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);
43
+ }
44
+ return this;
45
+ },
46
+ build() {
47
+ return source$1;
48
+ }
49
+ };
66
50
  }
67
51
 
68
- // src/source/storage/file-system.ts
52
+ //#endregion
53
+ //#region src/source/storage/file-system.ts
54
+ /**
55
+ * In memory file system.
56
+ */
69
57
  var FileSystem = class {
70
- constructor(inherit) {
71
- this.files = /* @__PURE__ */ new Map();
72
- this.folders = /* @__PURE__ */ new Map();
73
- if (inherit) {
74
- for (const [k, v] of inherit.folders) {
75
- this.folders.set(k, v);
76
- }
77
- for (const [k, v] of inherit.files) {
78
- this.files.set(k, v);
79
- }
80
- } else {
81
- this.folders.set("", []);
82
- }
83
- }
84
- read(path2) {
85
- return this.files.get(path2);
86
- }
87
- /**
88
- * get the direct children of folder (in virtual file path)
89
- */
90
- readDir(path2) {
91
- return this.folders.get(path2);
92
- }
93
- write(path2, file) {
94
- if (!this.files.has(path2)) {
95
- const dir = dirname(path2);
96
- this.makeDir(dir);
97
- this.readDir(dir)?.push(path2);
98
- }
99
- this.files.set(path2, file);
100
- }
101
- /**
102
- * Delete files at specified path.
103
- *
104
- * @param path - the target path.
105
- * @param [recursive=false] - if set to `true`, it will also delete directories.
106
- */
107
- delete(path2, recursive = false) {
108
- if (this.files.delete(path2)) return true;
109
- if (recursive) {
110
- const folder = this.folders.get(path2);
111
- if (!folder) return false;
112
- this.folders.delete(path2);
113
- for (const child of folder) {
114
- this.delete(child);
115
- }
116
- return true;
117
- }
118
- return false;
119
- }
120
- getFiles() {
121
- return Array.from(this.files.keys());
122
- }
123
- makeDir(path2) {
124
- const segments = splitPath(path2);
125
- for (let i = 0; i < segments.length; i++) {
126
- const segment = segments.slice(0, i + 1).join("/");
127
- if (this.folders.has(segment)) continue;
128
- this.folders.set(segment, []);
129
- this.folders.get(dirname(segment)).push(segment);
130
- }
131
- }
58
+ constructor(inherit) {
59
+ this.files = /* @__PURE__ */ new Map();
60
+ this.folders = /* @__PURE__ */ new Map();
61
+ if (inherit) {
62
+ for (const [k, v] of inherit.folders) this.folders.set(k, v);
63
+ for (const [k, v] of inherit.files) this.files.set(k, v);
64
+ } else this.folders.set("", []);
65
+ }
66
+ read(path$1) {
67
+ return this.files.get(path$1);
68
+ }
69
+ /**
70
+ * get the direct children of folder (in virtual file path)
71
+ */
72
+ readDir(path$1) {
73
+ return this.folders.get(path$1);
74
+ }
75
+ write(path$1, file) {
76
+ if (!this.files.has(path$1)) {
77
+ const dir = dirname(path$1);
78
+ this.makeDir(dir);
79
+ this.readDir(dir)?.push(path$1);
80
+ }
81
+ this.files.set(path$1, file);
82
+ }
83
+ /**
84
+ * Delete files at specified path.
85
+ *
86
+ * @param path - the target path.
87
+ * @param [recursive=false] - if set to `true`, it will also delete directories.
88
+ */
89
+ delete(path$1, recursive = false) {
90
+ if (this.files.delete(path$1)) return true;
91
+ if (recursive) {
92
+ const folder = this.folders.get(path$1);
93
+ if (!folder) return false;
94
+ this.folders.delete(path$1);
95
+ for (const child of folder) this.delete(child);
96
+ return true;
97
+ }
98
+ return false;
99
+ }
100
+ getFiles() {
101
+ return Array.from(this.files.keys());
102
+ }
103
+ makeDir(path$1) {
104
+ const segments = splitPath(path$1);
105
+ for (let i = 0; i < segments.length; i++) {
106
+ const segment = segments.slice(0, i + 1).join("/");
107
+ if (this.folders.has(segment)) continue;
108
+ this.folders.set(segment, []);
109
+ this.folders.get(dirname(segment)).push(segment);
110
+ }
111
+ }
132
112
  };
133
113
 
134
- // src/source/storage/content.ts
114
+ //#endregion
115
+ //#region src/source/storage/content.ts
135
116
  function isLocaleValid(locale) {
136
- return locale.length > 0 && !/\d+/.test(locale);
117
+ return locale.length > 0 && !/\d+/.test(locale);
137
118
  }
138
- var parsers = {
139
- dir(path2) {
140
- const [locale, ...segs] = path2.split("/");
141
- if (locale && segs.length > 0 && isLocaleValid(locale))
142
- return [segs.join("/"), locale];
143
- return [path2];
144
- },
145
- dot(path2) {
146
- const dir = dirname(path2);
147
- const base = basename(path2);
148
- const parts = base.split(".");
149
- if (parts.length < 3) return [path2];
150
- const [locale] = parts.splice(parts.length - 2, 1);
151
- if (!isLocaleValid(locale)) return [path2];
152
- return [joinPath(dir, parts.join(".")), locale];
153
- },
154
- none(path2) {
155
- return [path2];
156
- }
119
+ const parsers = {
120
+ dir(path$1) {
121
+ const [locale, ...segs] = path$1.split("/");
122
+ if (locale && segs.length > 0 && isLocaleValid(locale)) return [segs.join("/"), locale];
123
+ return [path$1];
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];
129
+ const [locale] = parts.splice(parts.length - 2, 1);
130
+ if (!isLocaleValid(locale)) return [path$1];
131
+ return [joinPath(dir, parts.join(".")), locale];
132
+ },
133
+ none(path$1) {
134
+ return [path$1];
135
+ }
157
136
  };
137
+ /**
138
+ * @param defaultLanguage - language to use when i18n is not configured.
139
+ * @returns a map of locale and its content storage.
140
+ *
141
+ * in the storage, locale codes are removed from file paths, hence the same file will have same file paths in every storage.
142
+ */
158
143
  function buildContentStorage(loaderConfig, defaultLanguage) {
159
- const {
160
- source: source2,
161
- plugins = [],
162
- i18n = {
163
- defaultLanguage,
164
- parser: "none",
165
- languages: [defaultLanguage]
166
- }
167
- } = loaderConfig;
168
- const parser = parsers[i18n.parser ?? "dot"];
169
- const storages = {};
170
- const normalized = /* @__PURE__ */ new Map();
171
- for (const inputFile of source2.files) {
172
- let file;
173
- if (inputFile.type === "page") {
174
- file = {
175
- format: "page",
176
- path: normalizePath(inputFile.path),
177
- // will be generated by the slugs plugin if unspecified
178
- slugs: inputFile.slugs,
179
- data: inputFile.data,
180
- absolutePath: inputFile.absolutePath
181
- };
182
- } else {
183
- file = {
184
- format: "meta",
185
- path: normalizePath(inputFile.path),
186
- absolutePath: inputFile.absolutePath,
187
- data: inputFile.data
188
- };
189
- }
190
- const [pathWithoutLocale, locale = i18n.defaultLanguage] = parser(
191
- file.path
192
- );
193
- const list = normalized.get(locale) ?? [];
194
- list.push({
195
- pathWithoutLocale,
196
- file
197
- });
198
- normalized.set(locale, list);
199
- }
200
- const fallbackLang = i18n.fallbackLanguage !== null ? i18n.fallbackLanguage ?? i18n.defaultLanguage : null;
201
- function scan(lang) {
202
- if (storages[lang]) return;
203
- let storage;
204
- if (fallbackLang && fallbackLang !== lang) {
205
- scan(fallbackLang);
206
- storage = new FileSystem(storages[fallbackLang]);
207
- } else {
208
- storage = new FileSystem();
209
- }
210
- for (const { pathWithoutLocale, file } of normalized.get(lang) ?? []) {
211
- storage.write(pathWithoutLocale, file);
212
- }
213
- const context = {
214
- storage
215
- };
216
- for (const plugin of plugins) {
217
- plugin.transformStorage?.(context);
218
- }
219
- storages[lang] = storage;
220
- }
221
- for (const lang of i18n.languages) scan(lang);
222
- return storages;
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 = {};
151
+ const normalized = /* @__PURE__ */ new Map();
152
+ for (const inputFile of source$1.files) {
153
+ let file;
154
+ if (inputFile.type === "page") file = {
155
+ format: "page",
156
+ path: normalizePath(inputFile.path),
157
+ slugs: inputFile.slugs,
158
+ data: inputFile.data,
159
+ absolutePath: inputFile.absolutePath
160
+ };
161
+ else file = {
162
+ format: "meta",
163
+ path: normalizePath(inputFile.path),
164
+ absolutePath: inputFile.absolutePath,
165
+ data: inputFile.data
166
+ };
167
+ const [pathWithoutLocale, locale = i18n.defaultLanguage] = parser(file.path);
168
+ const list = normalized.get(locale) ?? [];
169
+ list.push({
170
+ pathWithoutLocale,
171
+ file
172
+ });
173
+ normalized.set(locale, list);
174
+ }
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);
184
+ const context = { storage };
185
+ for (const plugin of plugins) plugin.transformStorage?.(context);
186
+ storages[lang] = storage;
187
+ }
188
+ for (const lang of i18n.languages) scan(lang);
189
+ return storages;
223
190
  }
224
- function normalizePath(path2) {
225
- const segments = splitPath(slash(path2));
226
- if (segments[0] === "." || segments[0] === "..")
227
- throw new Error("It must not start with './' or '../'");
228
- return segments.join("/");
191
+ /**
192
+ * @param path - Relative path
193
+ * @returns Normalized path, with no trailing/leading slashes
194
+ * @throws Throws error if path starts with `./` or `../`
195
+ */
196
+ function normalizePath(path$1) {
197
+ const segments = splitPath(slash(path$1));
198
+ if (segments[0] === "." || segments[0] === "..") throw new Error("It must not start with './' or '../'");
199
+ return segments.join("/");
229
200
  }
230
201
 
231
- // src/source/page-tree/transformer-fallback.ts
202
+ //#endregion
203
+ //#region src/source/page-tree/transformer-fallback.ts
232
204
  function transformerFallback() {
233
- const addedFiles = /* @__PURE__ */ new Set();
234
- return {
235
- root(root) {
236
- const isolatedStorage = new FileSystem();
237
- for (const file of this.storage.getFiles()) {
238
- if (addedFiles.has(file)) continue;
239
- const content = this.storage.read(file);
240
- if (content) isolatedStorage.write(file, content);
241
- }
242
- if (isolatedStorage.getFiles().length === 0) return root;
243
- root.fallback = this.builder.build(isolatedStorage, {
244
- ...this.options,
245
- id: `fallback-${root.$id ?? ""}`,
246
- generateFallback: false
247
- });
248
- addedFiles.clear();
249
- return root;
250
- },
251
- file(node, file) {
252
- if (file) addedFiles.add(file);
253
- return node;
254
- },
255
- folder(node, _dir, metaPath) {
256
- if (metaPath) addedFiles.add(metaPath);
257
- return node;
258
- }
259
- };
205
+ const addedFiles = /* @__PURE__ */ new Set();
206
+ return {
207
+ root(root) {
208
+ const isolatedStorage = new FileSystem();
209
+ for (const file of this.storage.getFiles()) {
210
+ if (addedFiles.has(file)) continue;
211
+ const content = this.storage.read(file);
212
+ if (content) isolatedStorage.write(file, content);
213
+ }
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
+ });
220
+ addedFiles.clear();
221
+ return root;
222
+ },
223
+ file(node, file) {
224
+ if (file) addedFiles.add(file);
225
+ return node;
226
+ },
227
+ folder(node, _dir, metaPath) {
228
+ if (metaPath) addedFiles.add(metaPath);
229
+ return node;
230
+ }
231
+ };
260
232
  }
261
233
 
262
- // src/source/page-tree/builder.ts
263
- var group = /^\((?<name>.+)\)$/;
264
- var link = /^(?<external>external:)?(?:\[(?<icon>[^\]]+)])?\[(?<name>[^\]]+)]\((?<url>[^)]+)\)$/;
265
- var separator = /^---(?:\[(?<icon>[^\]]+)])?(?<name>.+)---|^---$/;
266
- var rest = "...";
267
- var restReversed = "z...a";
268
- var extractPrefix = "...";
269
- var excludePrefix = "!";
234
+ //#endregion
235
+ //#region src/source/page-tree/builder.ts
236
+ const group = /^\((?<name>.+)\)$/;
237
+ const link = /^(?<external>external:)?(?:\[(?<icon>[^\]]+)])?\[(?<name>[^\]]+)]\((?<url>[^)]+)\)$/;
238
+ const separator = /^---(?:\[(?<icon>[^\]]+)])?(?<name>.+)---|^---$/;
239
+ const rest = "...";
240
+ const restReversed = "z...a";
241
+ const extractPrefix = "...";
242
+ const excludePrefix = "!";
270
243
  function createPageTreeBuilder(loaderConfig) {
271
- const { plugins = [], url, pageTree: defaultOptions = {} } = loaderConfig;
272
- return {
273
- build(storage, options = defaultOptions) {
274
- const key = "";
275
- return this.buildI18n({ [key]: storage }, options)[key];
276
- },
277
- buildI18n(storages, options = defaultOptions) {
278
- let nextId = 0;
279
- const out = {};
280
- const transformers = [];
281
- if (options.transformers) {
282
- transformers.push(...options.transformers);
283
- }
284
- for (const plugin of plugins) {
285
- if (plugin.transformPageTree)
286
- transformers.push(plugin.transformPageTree);
287
- }
288
- if (options.generateFallback ?? true) {
289
- transformers.push(transformerFallback());
290
- }
291
- for (const [locale, storage] of Object.entries(storages)) {
292
- let rootId = locale.length === 0 ? "root" : locale;
293
- if (options.id) rootId = `${options.id}-${rootId}`;
294
- out[locale] = createPageTreeBuilderUtils({
295
- rootId,
296
- transformers,
297
- builder: this,
298
- options,
299
- getUrl: url,
300
- locale,
301
- storage,
302
- storages,
303
- generateNodeId() {
304
- return "_" + nextId++;
305
- }
306
- }).root();
307
- }
308
- return out;
309
- }
310
- };
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;
275
+ }
276
+ };
311
277
  }
312
278
  function createFlattenPathResolver(storage) {
313
- const map = /* @__PURE__ */ new Map();
314
- const files = storage.getFiles();
315
- for (const file of files) {
316
- const content = storage.read(file);
317
- const flattenPath = file.substring(0, file.length - extname(file).length);
318
- map.set(flattenPath + "." + content.format, file);
319
- }
320
- return (name, format) => {
321
- return map.get(name + "." + format) ?? name;
322
- };
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
+ }
286
+ return (name, format) => {
287
+ return map.get(name + "." + format) ?? name;
288
+ };
323
289
  }
324
290
  function createPageTreeBuilderUtils(ctx) {
325
- const resolveFlattenPath = createFlattenPathResolver(ctx.storage);
326
- const visitedPaths = /* @__PURE__ */ new Set();
327
- function nextNodeId(localId = ctx.generateNodeId()) {
328
- return `${ctx.rootId}:${localId}`;
329
- }
330
- return {
331
- buildPaths(paths, reversed = false) {
332
- const items = [];
333
- const folders = [];
334
- const sortedPaths = paths.sort(
335
- (a, b) => a.localeCompare(b) * (reversed ? -1 : 1)
336
- );
337
- for (const path2 of sortedPaths) {
338
- const fileNode = this.file(path2);
339
- if (fileNode) {
340
- if (basename(path2, extname(path2)) === "index")
341
- items.unshift(fileNode);
342
- else items.push(fileNode);
343
- continue;
344
- }
345
- const dirNode = this.folder(path2, false);
346
- if (dirNode) folders.push(dirNode);
347
- }
348
- items.push(...folders);
349
- return items;
350
- },
351
- resolveFolderItem(folderPath, item) {
352
- if (item === rest || item === restReversed) return item;
353
- let match = separator.exec(item);
354
- if (match?.groups) {
355
- let node = {
356
- $id: nextNodeId(),
357
- type: "separator",
358
- icon: match.groups.icon,
359
- name: match.groups.name
360
- };
361
- for (const transformer of ctx.transformers) {
362
- if (!transformer.separator) continue;
363
- node = transformer.separator.call(ctx, node);
364
- }
365
- return [node];
366
- }
367
- match = link.exec(item);
368
- if (match?.groups) {
369
- const { icon, url, name, external } = match.groups;
370
- let node = {
371
- $id: nextNodeId(),
372
- type: "page",
373
- icon,
374
- name,
375
- url,
376
- external: external ? true : void 0
377
- };
378
- for (const transformer of ctx.transformers) {
379
- if (!transformer.file) continue;
380
- node = transformer.file.call(ctx, node);
381
- }
382
- return [node];
383
- }
384
- const isExcept = item.startsWith(excludePrefix);
385
- const isExtract = !isExcept && item.startsWith(extractPrefix);
386
- let filename = item;
387
- if (isExcept) {
388
- filename = item.slice(excludePrefix.length);
389
- } else if (isExtract) {
390
- filename = item.slice(extractPrefix.length);
391
- }
392
- const path2 = resolveFlattenPath(joinPath(folderPath, filename), "page");
393
- if (isExcept) {
394
- visitedPaths.add(path2);
395
- return [];
396
- }
397
- const dirNode = this.folder(path2, false);
398
- if (dirNode) {
399
- return isExtract ? dirNode.children : [dirNode];
400
- }
401
- const fileNode = this.file(path2);
402
- return fileNode ? [fileNode] : [];
403
- },
404
- folder(folderPath, isGlobalRoot) {
405
- const { storage, options, transformers } = ctx;
406
- const files = storage.readDir(folderPath);
407
- if (!files) return;
408
- const metaPath = resolveFlattenPath(joinPath(folderPath, "meta"), "meta");
409
- const indexPath = resolveFlattenPath(
410
- joinPath(folderPath, "index"),
411
- "page"
412
- );
413
- let meta = storage.read(metaPath);
414
- if (meta && meta.format !== "meta") meta = void 0;
415
- const metadata = meta?.data ?? {};
416
- const { root = isGlobalRoot, pages } = metadata;
417
- let index;
418
- let children;
419
- if (pages) {
420
- const resolved = pages.flatMap((item) => this.resolveFolderItem(folderPath, item));
421
- if (!root && !visitedPaths.has(indexPath)) {
422
- index = this.file(indexPath);
423
- }
424
- for (let i = 0; i < resolved.length; i++) {
425
- const item = resolved[i];
426
- if (item !== rest && item !== restReversed) continue;
427
- const items = this.buildPaths(
428
- files.filter((file) => !visitedPaths.has(file)),
429
- item === restReversed
430
- );
431
- resolved.splice(i, 1, ...items);
432
- break;
433
- }
434
- children = resolved;
435
- } else {
436
- if (!root && !visitedPaths.has(indexPath)) {
437
- index = this.file(indexPath);
438
- }
439
- children = this.buildPaths(
440
- files.filter((file) => !visitedPaths.has(file))
441
- );
442
- }
443
- let node = {
444
- type: "folder",
445
- name: metadata.title ?? index?.name ?? (() => {
446
- const folderName = basename(folderPath);
447
- return pathToName(group.exec(folderName)?.[1] ?? folderName);
448
- })(),
449
- icon: metadata.icon,
450
- root: metadata.root,
451
- defaultOpen: metadata.defaultOpen,
452
- description: metadata.description,
453
- collapsible: metadata.collapsible,
454
- index,
455
- children,
456
- $id: nextNodeId(folderPath),
457
- $ref: !options.noRef && meta ? {
458
- metaFile: metaPath
459
- } : void 0
460
- };
461
- visitedPaths.add(folderPath);
462
- for (const transformer of transformers) {
463
- if (!transformer.folder) continue;
464
- node = transformer.folder.call(ctx, node, folderPath, metaPath);
465
- }
466
- return node;
467
- },
468
- file(path2) {
469
- const { options, getUrl, storage, locale, transformers } = ctx;
470
- const page = storage.read(path2);
471
- if (page?.format !== "page") return;
472
- const { title, description, icon } = page.data;
473
- let item = {
474
- $id: nextNodeId(path2),
475
- type: "page",
476
- name: title ?? pathToName(basename(path2, extname(path2))),
477
- description,
478
- icon,
479
- url: getUrl(page.slugs, locale),
480
- $ref: !options.noRef ? {
481
- file: path2
482
- } : void 0
483
- };
484
- visitedPaths.add(path2);
485
- for (const transformer of transformers) {
486
- if (!transformer.file) continue;
487
- item = transformer.file.call(ctx, item, path2);
488
- }
489
- return item;
490
- },
491
- root() {
492
- const folder = this.folder("", true);
493
- let root = {
494
- $id: ctx.rootId,
495
- name: folder.name || "Docs",
496
- children: folder.children
497
- };
498
- for (const transformer of ctx.transformers) {
499
- if (!transformer.root) continue;
500
- root = transformer.root.call(ctx, root);
501
- }
502
- return root;
503
- }
504
- };
291
+ const resolveFlattenPath = createFlattenPathResolver(ctx.storage);
292
+ const visitedPaths = /* @__PURE__ */ new Set();
293
+ function nextNodeId(localId = ctx.generateNodeId()) {
294
+ return `${ctx.rootId}:${localId}`;
295
+ }
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)));
388
+ }
389
+ 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
404
+ };
405
+ visitedPaths.add(folderPath);
406
+ for (const transformer of transformers) {
407
+ if (!transformer.folder) continue;
408
+ node = transformer.folder.call(ctx, node, folderPath, metaPath);
409
+ }
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),
419
+ type: "page",
420
+ name: title ?? pathToName(basename(path$1, extname(path$1))),
421
+ description,
422
+ icon,
423
+ url: getUrl(page.slugs, locale),
424
+ $ref: !options.noRef ? { file: path$1 } : void 0
425
+ };
426
+ visitedPaths.add(path$1);
427
+ for (const transformer of transformers) {
428
+ if (!transformer.file) continue;
429
+ item = transformer.file.call(ctx, item, path$1);
430
+ }
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);
443
+ }
444
+ return root;
445
+ }
446
+ };
505
447
  }
448
+ /**
449
+ * Get item name from file name
450
+ *
451
+ * @param name - file name
452
+ */
506
453
  function pathToName(name) {
507
- const result = [];
508
- for (const c of name) {
509
- if (result.length === 0) result.push(c.toLocaleUpperCase());
510
- else if (c === "-") result.push(" ");
511
- else result.push(c);
512
- }
513
- return result.join("");
454
+ const result = [];
455
+ for (const c of name) if (result.length === 0) result.push(c.toLocaleUpperCase());
456
+ else if (c === "-") result.push(" ");
457
+ else result.push(c);
458
+ return result.join("");
514
459
  }
515
460
 
516
- // src/source/plugins/index.ts
517
- var priorityMap = {
518
- pre: 1,
519
- default: 0,
520
- post: -1
521
- };
522
- function buildPlugins(plugins, sort = true) {
523
- const flatten = [];
524
- for (const plugin of plugins) {
525
- if (Array.isArray(plugin)) flatten.push(...buildPlugins(plugin, false));
526
- else if (plugin) flatten.push(plugin);
527
- }
528
- if (sort)
529
- return flatten.sort(
530
- (a, b) => priorityMap[b.enforce ?? "default"] - priorityMap[a.enforce ?? "default"]
531
- );
532
- return flatten;
533
- }
534
-
535
- // src/source/plugins/slugs.ts
536
- function slugsPlugin(slugsFn) {
537
- function isIndex(file) {
538
- return basename(file, extname(file)) === "index";
539
- }
540
- return {
541
- name: "fumadocs:slugs",
542
- transformStorage({ storage }) {
543
- const indexFiles = /* @__PURE__ */ new Set();
544
- const taken = /* @__PURE__ */ new Set();
545
- const autoIndex = slugsFn === void 0;
546
- for (const path2 of storage.getFiles()) {
547
- const file = storage.read(path2);
548
- if (!file || file.format !== "page" || file.slugs) continue;
549
- if (isIndex(path2) && autoIndex) {
550
- indexFiles.add(path2);
551
- continue;
552
- }
553
- file.slugs = slugsFn ? slugsFn({ path: path2 }) : getSlugs(path2);
554
- const key = file.slugs.join("/");
555
- if (taken.has(key)) throw new Error("Duplicated slugs");
556
- taken.add(key);
557
- }
558
- for (const path2 of indexFiles) {
559
- const file = storage.read(path2);
560
- if (file?.format !== "page") continue;
561
- file.slugs = getSlugs(path2);
562
- if (taken.has(file.slugs.join("/"))) file.slugs.push("index");
563
- }
564
- }
565
- };
566
- }
567
- var GroupRegex = /^\(.+\)$/;
568
- function getSlugs(file) {
569
- const dir = dirname(file);
570
- const name = basename(file, extname(file));
571
- const slugs = [];
572
- for (const seg of dir.split("/")) {
573
- if (seg.length > 0 && !GroupRegex.test(seg)) slugs.push(encodeURI(seg));
574
- }
575
- if (GroupRegex.test(name))
576
- throw new Error(`Cannot use folder group in file names: ${file}`);
577
- if (name !== "index") {
578
- slugs.push(encodeURI(name));
579
- }
580
- return slugs;
581
- }
582
-
583
- // src/source/loader.ts
584
- import path from "path";
461
+ //#endregion
462
+ //#region src/source/loader.ts
585
463
  function indexPages(storages, { url }) {
586
- const result = {
587
- // (locale.slugs -> page)
588
- pages: /* @__PURE__ */ new Map(),
589
- // (locale.path -> page)
590
- pathToMeta: /* @__PURE__ */ new Map(),
591
- // (locale.path -> meta)
592
- pathToPage: /* @__PURE__ */ new Map()
593
- };
594
- for (const [lang, storage] of Object.entries(storages)) {
595
- for (const filePath of storage.getFiles()) {
596
- const item = storage.read(filePath);
597
- const path2 = `${lang}.${filePath}`;
598
- if (item.format === "meta") {
599
- result.pathToMeta.set(path2, {
600
- path: item.path,
601
- absolutePath: item.absolutePath,
602
- data: item.data
603
- });
604
- continue;
605
- }
606
- const page = {
607
- absolutePath: item.absolutePath,
608
- path: item.path,
609
- url: url(item.slugs, lang),
610
- slugs: item.slugs,
611
- data: item.data,
612
- locale: lang
613
- };
614
- result.pathToPage.set(path2, page);
615
- result.pages.set(`${lang}.${page.slugs.join("/")}`, page);
616
- }
617
- }
618
- return result;
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;
479
+ }
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;
619
492
  }
620
493
  function createGetUrl(baseUrl, i18n) {
621
- const baseSlugs = baseUrl.split("/");
622
- return (slugs, locale) => {
623
- const hideLocale = i18n?.hideLocale ?? "never";
624
- let urlLocale;
625
- if (hideLocale === "never") {
626
- urlLocale = locale;
627
- } else if (hideLocale === "default-locale" && locale !== i18n?.defaultLanguage) {
628
- urlLocale = locale;
629
- }
630
- const paths = [...baseSlugs, ...slugs];
631
- if (urlLocale) paths.unshift(urlLocale);
632
- return `/${paths.filter((v) => v.length > 0).join("/")}`;
633
- };
494
+ const baseSlugs = baseUrl.split("/");
495
+ return (slugs, locale) => {
496
+ const hideLocale = i18n?.hideLocale ?? "never";
497
+ let urlLocale;
498
+ if (hideLocale === "never") urlLocale = locale;
499
+ else if (hideLocale === "default-locale" && locale !== i18n?.defaultLanguage) urlLocale = locale;
500
+ const paths = [...baseSlugs, ...slugs];
501
+ if (urlLocale) paths.unshift(urlLocale);
502
+ return `/${paths.filter((v) => v.length > 0).join("/")}`;
503
+ };
634
504
  }
635
505
  function loader(...args) {
636
- const loaderConfig = args.length === 2 ? resolveConfig(args[0], args[1]) : resolveConfig(args[0].source, args[0]);
637
- const { i18n } = loaderConfig;
638
- const defaultLanguage = i18n?.defaultLanguage ?? "";
639
- const storages = buildContentStorage(loaderConfig, defaultLanguage);
640
- const walker = indexPages(storages, loaderConfig);
641
- const builder = createPageTreeBuilder(loaderConfig);
642
- let pageTrees;
643
- function getPageTrees() {
644
- return pageTrees ??= builder.buildI18n(storages);
645
- }
646
- return {
647
- _i18n: i18n,
648
- get pageTree() {
649
- const trees = getPageTrees();
650
- return i18n ? trees : trees[defaultLanguage];
651
- },
652
- set pageTree(v) {
653
- if (i18n) {
654
- pageTrees = v;
655
- } else {
656
- pageTrees ??= {};
657
- pageTrees[defaultLanguage] = v;
658
- }
659
- },
660
- getPageByHref(href, { dir = "", language = defaultLanguage } = {}) {
661
- const [value, hash] = href.split("#", 2);
662
- let target;
663
- if (value.startsWith("./")) {
664
- const path2 = joinPath(dir, value);
665
- target = walker.pathToPage.get(`${language}.${path2}`);
666
- } else {
667
- target = this.getPages(language).find((item) => item.url === value);
668
- }
669
- if (target)
670
- return {
671
- page: target,
672
- hash
673
- };
674
- },
675
- resolveHref(href, parent) {
676
- if (href.startsWith("./")) {
677
- const target = this.getPageByHref(href, {
678
- dir: path.dirname(parent.path),
679
- language: parent.locale
680
- });
681
- if (target) {
682
- return target.hash ? `${target.page.url}#${target.hash}` : target.page.url;
683
- }
684
- }
685
- return href;
686
- },
687
- getPages(language) {
688
- const pages = [];
689
- for (const [key, value] of walker.pages.entries()) {
690
- if (language === void 0 || key.startsWith(`${language}.`)) {
691
- pages.push(value);
692
- }
693
- }
694
- return pages;
695
- },
696
- getLanguages() {
697
- const list = [];
698
- if (!i18n) return list;
699
- for (const language of i18n.languages) {
700
- list.push({
701
- language,
702
- pages: this.getPages(language)
703
- });
704
- }
705
- return list;
706
- },
707
- // the slugs plugin generates encoded slugs by default.
708
- // we can assume page slugs are always URI encoded.
709
- getPage(slugs = [], language = defaultLanguage) {
710
- let page = walker.pages.get(`${language}.${slugs.join("/")}`);
711
- if (page) return page;
712
- page = walker.pages.get(`${language}.${slugs.map(decodeURI).join("/")}`);
713
- if (page) return page;
714
- },
715
- getNodeMeta(node, language = defaultLanguage) {
716
- const ref = node.$ref?.metaFile;
717
- if (!ref) return;
718
- return walker.pathToMeta.get(`${language}.${ref}`);
719
- },
720
- getNodePage(node, language = defaultLanguage) {
721
- const ref = node.$ref?.file;
722
- if (!ref) return;
723
- return walker.pathToPage.get(`${language}.${ref}`);
724
- },
725
- getPageTree(locale = defaultLanguage) {
726
- const trees = getPageTrees();
727
- return trees[locale] ?? trees[defaultLanguage];
728
- },
729
- // @ts-expect-error -- ignore this
730
- generateParams(slug, lang) {
731
- if (i18n) {
732
- return this.getLanguages().flatMap(
733
- (entry) => entry.pages.map((page) => ({
734
- [slug ?? "slug"]: page.slugs,
735
- [lang ?? "lang"]: entry.language
736
- }))
737
- );
738
- }
739
- return this.getPages().map((page) => ({
740
- [slug ?? "slug"]: page.slugs
741
- }));
742
- },
743
- async serializePageTree(tree) {
744
- const { renderToString } = await import("react-dom/server.edge");
745
- return visit(tree, (node) => {
746
- node = { ...node };
747
- if ("icon" in node && node.icon) {
748
- node.icon = renderToString(node.icon);
749
- }
750
- if (node.name) {
751
- node.name = renderToString(node.name);
752
- }
753
- if ("children" in node) {
754
- node.children = [...node.children];
755
- }
756
- return node;
757
- });
758
- }
759
- };
506
+ const loaderConfig = args.length === 2 ? resolveConfig(args[0], args[1]) : resolveConfig(args[0].source, args[0]);
507
+ 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);
512
+ let pageTrees;
513
+ function getPageTrees() {
514
+ return pageTrees ??= builder.buildI18n(storages);
515
+ }
516
+ return {
517
+ _i18n: i18n,
518
+ get pageTree() {
519
+ const trees = getPageTrees();
520
+ return i18n ? trees : trees[defaultLanguage];
521
+ },
522
+ set pageTree(v) {
523
+ if (i18n) pageTrees = v;
524
+ else {
525
+ pageTrees ??= {};
526
+ pageTrees[defaultLanguage] = v;
527
+ }
528
+ },
529
+ getPageByHref(href, { dir = "", language = defaultLanguage } = {}) {
530
+ const [value, hash] = href.split("#", 2);
531
+ let target;
532
+ if (value.startsWith("./")) {
533
+ const path$1 = joinPath(dir, value);
534
+ target = walker.pathToPage.get(`${language}.${path$1}`);
535
+ } else target = this.getPages(language).find((item) => item.url === value);
536
+ if (target) return {
537
+ page: target,
538
+ hash
539
+ };
540
+ },
541
+ resolveHref(href, parent) {
542
+ if (href.startsWith("./")) {
543
+ const target = this.getPageByHref(href, {
544
+ dir: path.dirname(parent.path),
545
+ language: parent.locale
546
+ });
547
+ if (target) return target.hash ? `${target.page.url}#${target.hash}` : target.page.url;
548
+ }
549
+ return href;
550
+ },
551
+ 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;
555
+ },
556
+ getLanguages() {
557
+ const list = [];
558
+ if (!i18n) return list;
559
+ for (const language of i18n.languages) list.push({
560
+ language,
561
+ pages: this.getPages(language)
562
+ });
563
+ return list;
564
+ },
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;
570
+ },
571
+ getNodeMeta(node, language = defaultLanguage) {
572
+ const ref = node.$ref?.metaFile;
573
+ if (!ref) return;
574
+ return walker.pathToMeta.get(`${language}.${ref}`);
575
+ },
576
+ getNodePage(node, language = defaultLanguage) {
577
+ const ref = node.$ref?.file;
578
+ if (!ref) return;
579
+ return walker.pathToPage.get(`${language}.${ref}`);
580
+ },
581
+ getPageTree(locale = defaultLanguage) {
582
+ const trees = getPageTrees();
583
+ return trees[locale] ?? trees[defaultLanguage];
584
+ },
585
+ generateParams(slug, lang) {
586
+ if (i18n) return this.getLanguages().flatMap((entry) => entry.pages.map((page) => ({
587
+ [slug ?? "slug"]: page.slugs,
588
+ [lang ?? "lang"]: entry.language
589
+ })));
590
+ return this.getPages().map((page) => ({ [slug ?? "slug"]: page.slugs }));
591
+ },
592
+ async serializePageTree(tree) {
593
+ 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
+ });
601
+ }
602
+ };
760
603
  }
761
- function resolveConfig(source2, { slugs, icon, plugins = [], baseUrl, url, ...base }) {
762
- let config = {
763
- ...base,
764
- url: url ? (...args) => normalizeUrl(url(...args)) : createGetUrl(baseUrl, base.i18n),
765
- source: source2,
766
- plugins: buildPlugins([
767
- slugsPlugin(slugs),
768
- icon && iconPlugin(icon),
769
- ...typeof plugins === "function" ? plugins({
770
- typedPlugin: (plugin) => plugin
771
- }) : plugins
772
- ])
773
- };
774
- for (const plugin of config.plugins ?? []) {
775
- const result = plugin.config?.(config);
776
- if (result) config = result;
777
- }
778
- return config;
604
+ function resolveConfig(source$1, { slugs, icon, plugins = [], baseUrl, url, ...base }) {
605
+ let config = {
606
+ ...base,
607
+ url: url ? (...args) => normalizeUrl(url(...args)) : createGetUrl(baseUrl, base.i18n),
608
+ source: source$1,
609
+ plugins: buildPlugins([
610
+ icon && iconPlugin(icon),
611
+ ...typeof plugins === "function" ? plugins({ typedPlugin: (plugin) => plugin }) : plugins,
612
+ slugsPlugin(slugs)
613
+ ])
614
+ };
615
+ for (const plugin of config.plugins ?? []) {
616
+ const result = plugin.config?.(config);
617
+ if (result) config = result;
618
+ }
619
+ return config;
779
620
  }
780
- export {
781
- FileSystem,
782
- path_exports as PathUtils,
783
- createGetUrl,
784
- getSlugs,
785
- loader,
786
- multiple,
787
- source,
788
- update
621
+ const priorityMap = {
622
+ pre: 1,
623
+ default: 0,
624
+ post: -1
789
625
  };
626
+ function buildPlugins(plugins, sort = true) {
627
+ const flatten = [];
628
+ for (const plugin of plugins) if (Array.isArray(plugin)) flatten.push(...buildPlugins(plugin, false));
629
+ else if (plugin) flatten.push(plugin);
630
+ if (sort) return flatten.sort((a, b) => priorityMap[b.enforce ?? "default"] - priorityMap[a.enforce ?? "default"]);
631
+ return flatten;
632
+ }
633
+
634
+ //#endregion
635
+ export { FileSystem, path_exports as PathUtils, createGetUrl, getSlugs, loader, multiple, source, update };
636
+ //# sourceMappingURL=index.js.map