fumadocs-core 9.0.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { R as Root } from './page-tree-izSPERQk.js';
1
+ import { R as Root } from './page-tree-mLHMYx2B.js';
2
2
  import 'react';
3
3
 
4
4
  interface BreadcrumbItem {
@@ -20,6 +20,7 @@ interface Folder {
20
20
  type: 'folder';
21
21
  name: string;
22
22
  root?: boolean;
23
+ defaultOpen?: boolean;
23
24
  index?: Item;
24
25
  icon?: ReactElement;
25
26
  children: Node[];
@@ -1,7 +1,7 @@
1
1
  import { T as TableOfContents } from '../get-toc-YF_TdazL.js';
2
2
  export { a as TOCItemType, g as getTableOfContents } from '../get-toc-YF_TdazL.js';
3
- import { N as Node, I as Item, R as Root } from '../page-tree-izSPERQk.js';
4
- export { p as PageTree } from '../page-tree-izSPERQk.js';
3
+ import { N as Node, I as Item, R as Root } from '../page-tree-mLHMYx2B.js';
4
+ export { p as PageTree } from '../page-tree-mLHMYx2B.js';
5
5
  import 'react';
6
6
 
7
7
  /**
@@ -1,5 +1,22 @@
1
1
  import { ReactElement } from 'react';
2
- import { R as Root } from '../page-tree-izSPERQk.js';
2
+ import { R as Root } from '../page-tree-mLHMYx2B.js';
3
+
4
+ interface FileInfo {
5
+ locale?: string;
6
+ /**
7
+ * Original path of file
8
+ */
9
+ path: string;
10
+ /**
11
+ * File path without extension
12
+ */
13
+ flattenedPath: string;
14
+ /**
15
+ * File name without locale and extension
16
+ */
17
+ name: string;
18
+ dirname: string;
19
+ }
3
20
 
4
21
  interface LoadOptions {
5
22
  files: VirtualFile[];
@@ -15,10 +32,12 @@ interface VirtualFile {
15
32
  }
16
33
  interface LoadResult {
17
34
  storage: Storage;
35
+ }
36
+ type Transformer = (context: {
37
+ storage: Storage;
18
38
  getSlugs: (info: FileInfo) => string[];
19
39
  getUrl: (slugs: string[], locale?: string) => string;
20
- data: Record<string, unknown>;
21
- }
40
+ }) => void;
22
41
  declare function load(options: LoadOptions): LoadResult;
23
42
 
24
43
  interface LoaderConfig {
@@ -54,7 +73,7 @@ interface Source<Config extends SourceConfig> {
54
73
  }
55
74
  interface LoaderOutput<Config extends LoaderConfig> {
56
75
  pageTree: Config['i18n'] extends true ? Record<string, Root> : Root;
57
- files: Node<Config['source']['metaData'], Config['source']['pageData']>[];
76
+ files: (Meta<Config['source']['metaData']> | Page<Config['source']['pageData']>)[];
58
77
  /**
59
78
  * Get list of pages from language, empty if language hasn't specified
60
79
  *
@@ -72,27 +91,12 @@ declare function loader<Options extends LoaderOptions>(options: Options): Loader
72
91
  i18n: Options['languages'] extends string[] ? true : false;
73
92
  }>;
74
93
 
75
- interface FileInfo {
76
- locale?: string;
77
- /**
78
- * Original path of file
79
- */
80
- path: string;
81
- /**
82
- * File path without extension
83
- */
84
- flattenedPath: string;
85
- /**
86
- * File name without locale and extension
87
- */
88
- name: string;
89
- dirname: string;
90
- }
91
94
  interface MetaData {
92
95
  icon?: string;
93
96
  title?: string;
94
97
  root?: boolean;
95
98
  pages?: string[];
99
+ defaultOpen?: boolean;
96
100
  }
97
101
  interface PageData {
98
102
  icon?: string;
@@ -100,7 +104,6 @@ interface PageData {
100
104
  }
101
105
  type InferPageType<Utils extends LoaderOutput<any>> = Utils extends LoaderOutput<infer Config> ? Page<Config['source']['pageData']> : never;
102
106
  type InferMetaType<Utils extends LoaderOutput<any>> = Utils extends LoaderOutput<infer Config> ? Meta<Config['source']['metaData']> : never;
103
- type Transformer = (context: LoadResult) => void;
104
107
 
105
108
  interface Meta<Data extends MetaData = MetaData> {
106
109
  type: 'meta';
@@ -117,9 +120,8 @@ interface Page<Data extends PageData = PageData> {
117
120
  interface Folder<MD extends MetaData = MetaData, PD extends PageData = PageData> {
118
121
  type: 'folder';
119
122
  file: FileInfo;
120
- children: Node<MD, PD>[];
123
+ children: (Meta<MD> | Page<PD> | Folder<MD, PD>)[];
121
124
  }
122
- type Node<MD extends MetaData = MetaData, PD extends PageData = PageData> = Meta<MD> | Page<PD> | Folder;
123
125
  /**
124
126
  * A virtual file system that solves inconsistent behaviours
125
127
  *
@@ -131,10 +133,17 @@ declare class Storage {
131
133
  private rootFolder;
132
134
  constructor();
133
135
  /**
134
- * Read a file, it doesn't need an extension
135
136
  * @param path - flattened path
136
137
  */
137
- read(path: string): Page | Meta | undefined;
138
+ private read;
139
+ /**
140
+ * @param path - flattened path
141
+ */
142
+ readPage(path: string): Page | undefined;
143
+ /**
144
+ * @param path - flattened path
145
+ */
146
+ readMeta(path: string): Meta | undefined;
138
147
  readDir(path: string): Folder | undefined;
139
148
  root(): Folder;
140
149
  write(path: string, file: Omit<Page, 'file'> | Omit<Meta, 'file'>): void;
@@ -144,12 +153,11 @@ declare class Storage {
144
153
 
145
154
  type fileSystem_Folder<MD extends MetaData = MetaData, PD extends PageData = PageData> = Folder<MD, PD>;
146
155
  type fileSystem_Meta<Data extends MetaData = MetaData> = Meta<Data>;
147
- type fileSystem_Node<MD extends MetaData = MetaData, PD extends PageData = PageData> = Node<MD, PD>;
148
156
  type fileSystem_Page<Data extends PageData = PageData> = Page<Data>;
149
157
  type fileSystem_Storage = Storage;
150
158
  declare const fileSystem_Storage: typeof Storage;
151
159
  declare namespace fileSystem {
152
- export { type fileSystem_Folder as Folder, type fileSystem_Meta as Meta, type fileSystem_Node as Node, type fileSystem_Page as Page, fileSystem_Storage as Storage };
160
+ export { type fileSystem_Folder as Folder, type fileSystem_Meta as Meta, type fileSystem_Page as Page, fileSystem_Storage as Storage };
153
161
  }
154
162
 
155
163
  interface BuildPageTreeOptionsWithI18n {
@@ -168,4 +176,4 @@ interface CreatePageTreeBuilderOptions {
168
176
  }
169
177
  declare function createPageTreeBuilder({ storage, resolveIcon, }: CreatePageTreeBuilderOptions): PageTreeBuilder;
170
178
 
171
- export { type BuildPageTreeOptionsWithI18n, type CreatePageTreeBuilderOptions, type FileInfo, fileSystem as FileSystem, type InferMetaType, type InferPageType, type LoadOptions, type LoadResult, type LoaderOptions, type LoaderOutput, type MetaData, type PageData, type PageTreeBuilder, type Source, type Transformer, type VirtualFile, createPageTreeBuilder, load, loader };
179
+ export { type BuildPageTreeOptionsWithI18n, type CreatePageTreeBuilderOptions, fileSystem as FileSystem, type InferMetaType, type InferPageType, type LoadOptions, type LoadResult, type LoaderOptions, type LoaderOutput, type MetaData, type PageData, type PageTreeBuilder, type Source, type Transformer, type VirtualFile, createPageTreeBuilder, load, loader };
@@ -3,50 +3,41 @@ import {
3
3
  } from "../chunk-UWEEHUJV.js";
4
4
  import {
5
5
  __export,
6
- __spreadProps,
7
6
  __spreadValues
8
7
  } from "../chunk-WEAGW6MQ.js";
9
8
 
10
9
  // src/source/path.ts
11
10
  import { parse } from "path";
12
- function parseFilePath(path) {
13
- const parsed = parse(path);
14
- const dir = slash(parsed.dir);
15
- const flattenedPath = joinPaths([dir, parsed.name]);
11
+ function parseFilePath(path2) {
12
+ const slashedPath = slash(path2);
13
+ const parsed = parse(slashedPath);
14
+ const flattenedPath = joinPaths([parsed.dir, parsed.name]);
16
15
  const [name, locale] = parsed.name.split(".");
17
16
  return {
18
- dirname: dir,
17
+ dirname: parsed.dir,
19
18
  name,
20
19
  flattenedPath,
21
20
  locale,
22
- path
21
+ path: slashedPath
23
22
  };
24
23
  }
25
- function isRelative(path, root) {
26
- return path.startsWith(root);
27
- }
28
- function getRelativePath(path, root) {
29
- if (!isRelative(path, root))
30
- throw new Error("Invalid path");
31
- return splitPath(path.substring(root.length)).join("/");
32
- }
33
- function parseFolderPath(path) {
34
- const parsed = parse(path);
35
- const dir = slash(parsed.dir);
24
+ function parseFolderPath(path2) {
25
+ const slashedPath = slash(path2);
26
+ const parsed = parse(slashedPath);
36
27
  const [name, locale] = parsed.base.split(".");
37
28
  return {
38
- dirname: dir,
29
+ dirname: parsed.dir,
39
30
  name,
40
- flattenedPath: path,
31
+ flattenedPath: slashedPath,
41
32
  locale,
42
- path
33
+ path: slashedPath
43
34
  };
44
35
  }
45
- function splitPath(path) {
46
- return path.split("/").filter((p) => p.length > 0);
36
+ function splitPath(path2) {
37
+ return path2.split("/").filter((p) => p.length > 0);
47
38
  }
48
39
  function joinPaths(paths, slashMode = "none") {
49
- const joined = paths.flatMap((path) => splitPath(path)).join("/");
40
+ const joined = paths.flatMap((path2) => splitPath(path2)).join("/");
50
41
  switch (slashMode) {
51
42
  case "leading":
52
43
  return `/${joined}`;
@@ -58,6 +49,7 @@ function joinPaths(paths, slashMode = "none") {
58
49
  }
59
50
 
60
51
  // src/source/page-tree-builder.ts
52
+ var external = new RegExp("\\[(?<text>.+)\\]\\((?<url>.+)\\)");
61
53
  var separator = new RegExp("---(?<name>.*?)---");
62
54
  var rest = "...";
63
55
  var extractor = new RegExp("\\.\\.\\.(?<name>.+)");
@@ -78,58 +70,73 @@ function buildAll(nodes, ctx, skipIndex) {
78
70
  output.push(treeNode);
79
71
  }
80
72
  if (node.type === "folder") {
81
- output.push(buildFolderNode(node, ctx));
73
+ output.push(buildFolderNode(node, false, ctx));
82
74
  }
83
75
  }
84
76
  return output;
85
77
  }
86
78
  function getFolderMeta(folder, ctx) {
87
79
  var _a;
88
- let meta = ctx.storage.read(joinPaths([folder.file.path, "meta"]));
80
+ let meta = ctx.storage.readMeta(joinPaths([folder.file.path, "meta"]));
89
81
  if (ctx.lang) {
90
- meta = (_a = ctx.storage.read(joinPaths([folder.file.path, `meta.${ctx.lang}`]))) != null ? _a : meta;
82
+ meta = (_a = ctx.storage.readMeta(joinPaths([folder.file.path, `meta.${ctx.lang}`]))) != null ? _a : meta;
83
+ }
84
+ return meta;
85
+ }
86
+ function resolveFolderItem(folder, item, ctx, addedNodePaths) {
87
+ var _a, _b, _c;
88
+ if (item === rest)
89
+ return "...";
90
+ const separateResult = separator.exec(item);
91
+ if (separateResult == null ? void 0 : separateResult.groups) {
92
+ return [
93
+ {
94
+ type: "separator",
95
+ name: separateResult.groups.name
96
+ }
97
+ ];
98
+ }
99
+ const externalResult = external.exec(item);
100
+ if (externalResult == null ? void 0 : externalResult.groups) {
101
+ return [
102
+ {
103
+ type: "page",
104
+ name: externalResult.groups.text,
105
+ url: externalResult.groups.url,
106
+ external: true
107
+ }
108
+ ];
109
+ }
110
+ const extractResult = extractor.exec(item);
111
+ const path2 = joinPaths([
112
+ folder.file.path,
113
+ (_b = (_a = extractResult == null ? void 0 : extractResult.groups) == null ? void 0 : _a.name) != null ? _b : item
114
+ ]);
115
+ const itemNode = (_c = ctx.storage.readDir(path2)) != null ? _c : ctx.storage.readPage(path2);
116
+ if (!itemNode)
117
+ return [];
118
+ addedNodePaths.add(itemNode.file.path);
119
+ if (itemNode.type === "folder") {
120
+ const node = buildFolderNode(itemNode, false, ctx);
121
+ return extractResult ? node.children : [node];
91
122
  }
92
- if ((meta == null ? void 0 : meta.type) === "meta")
93
- return meta;
123
+ return [buildFileNode(itemNode, ctx)];
94
124
  }
95
- function buildFolderNode(folder, ctx, root = false) {
125
+ function buildFolderNode(folder, defaultIsRoot, ctx) {
96
126
  var _a, _b, _c, _d, _e;
97
- const indexNode = folder.children.find(
98
- (node) => node.type === "page" && node.file.name === "index"
127
+ const indexFile = ctx.storage.readPage(
128
+ joinPaths([folder.file.flattenedPath, "index"])
99
129
  );
100
- const index = indexNode ? buildFileNode(indexNode, ctx) : void 0;
130
+ const index = indexFile ? buildFileNode(indexFile, ctx) : void 0;
101
131
  const meta = (_a = getFolderMeta(folder, ctx)) == null ? void 0 : _a.data;
102
132
  let children;
103
133
  if (!meta) {
104
- children = buildAll(folder.children, ctx, !root);
134
+ children = buildAll(folder.children, ctx, !defaultIsRoot);
105
135
  } else {
106
- const isRoot = (_b = meta.root) != null ? _b : root;
136
+ const isRoot = (_b = meta.root) != null ? _b : defaultIsRoot;
107
137
  const addedNodePaths = /* @__PURE__ */ new Set();
108
138
  const resolved = (_c = meta.pages) == null ? void 0 : _c.flatMap((item) => {
109
- var _a2, _b2, _c2;
110
- if (item === rest)
111
- return "...";
112
- const result = separator.exec(item);
113
- if (result == null ? void 0 : result.groups) {
114
- return {
115
- type: "separator",
116
- name: result.groups.name
117
- };
118
- }
119
- const extractResult = extractor.exec(item);
120
- const extractName = (_b2 = (_a2 = extractResult == null ? void 0 : extractResult.groups) == null ? void 0 : _a2.name) != null ? _b2 : item;
121
- const itemNode = (_c2 = ctx.storage.readDir(joinPaths([folder.file.path, extractName]))) != null ? _c2 : ctx.storage.read(joinPaths([folder.file.path, extractName]));
122
- if (!itemNode)
123
- return [];
124
- addedNodePaths.add(itemNode.file.path);
125
- if (itemNode.type === "folder") {
126
- const node = buildFolderNode(itemNode, ctx);
127
- return (extractResult == null ? void 0 : extractResult.groups) ? node.children : node;
128
- }
129
- if (itemNode.type === "page") {
130
- return buildFileNode(itemNode, ctx);
131
- }
132
- return [];
139
+ return resolveFolderItem(folder, item, ctx, addedNodePaths);
133
140
  });
134
141
  const restNodes = buildAll(
135
142
  folder.children.filter((node) => !addedNodePaths.has(node.file.path)),
@@ -149,6 +156,7 @@ function buildFolderNode(folder, ctx, root = false) {
149
156
  name: (_e = (_d = meta == null ? void 0 : meta.title) != null ? _d : index == null ? void 0 : index.name) != null ? _e : pathToName(folder.file.name),
150
157
  icon: ctx.resolveIcon(meta == null ? void 0 : meta.icon),
151
158
  root: meta == null ? void 0 : meta.root,
159
+ defaultOpen: meta == null ? void 0 : meta.defaultOpen,
152
160
  index,
153
161
  children
154
162
  };
@@ -156,8 +164,10 @@ function buildFolderNode(folder, ctx, root = false) {
156
164
  function buildFileNode(page, ctx) {
157
165
  let localePage = page;
158
166
  if (ctx.lang) {
159
- const result = ctx.storage.read(`${page.file.flattenedPath}.${ctx.lang}`);
160
- if ((result == null ? void 0 : result.type) === "page")
167
+ const result = ctx.storage.readPage(
168
+ `${page.file.flattenedPath}.${ctx.lang}`
169
+ );
170
+ if (result)
161
171
  localePage = result;
162
172
  }
163
173
  return {
@@ -169,7 +179,7 @@ function buildFileNode(page, ctx) {
169
179
  }
170
180
  function build(ctx) {
171
181
  const root = ctx.storage.root();
172
- const folder = buildFolderNode(root, ctx, true);
182
+ const folder = buildFolderNode(root, true, ctx);
173
183
  return {
174
184
  name: folder.name,
175
185
  children: folder.children
@@ -179,33 +189,38 @@ function createPageTreeBuilder({
179
189
  storage,
180
190
  resolveIcon = () => void 0
181
191
  }) {
182
- const context = {
183
- storage,
184
- resolveIcon(icon) {
185
- if (!icon)
186
- return;
187
- return resolveIcon(icon);
188
- }
189
- };
192
+ function getContext(builder, locale) {
193
+ return {
194
+ storage,
195
+ lang: locale,
196
+ resolveIcon(icon) {
197
+ if (!icon)
198
+ return;
199
+ return resolveIcon(icon);
200
+ },
201
+ builder
202
+ };
203
+ }
190
204
  return {
191
205
  build() {
192
- return build(context);
206
+ return build(getContext(this));
193
207
  },
194
208
  buildI18n({ languages = [] } = {}) {
195
209
  const entries = languages.map((lang) => {
196
- const tree = build(__spreadProps(__spreadValues({}, context), {
197
- lang
198
- }));
210
+ const tree = build(getContext(this, lang));
199
211
  return [lang, tree];
200
212
  });
201
213
  return Object.fromEntries(entries);
202
214
  }
203
215
  };
204
216
  }
205
- function pathToName(path) {
206
- return path.slice(0, 1).toUpperCase() + path.slice(1);
217
+ function pathToName(path2) {
218
+ return path2.slice(0, 1).toUpperCase() + path2.slice(1);
207
219
  }
208
220
 
221
+ // src/source/load.ts
222
+ import * as path from "path";
223
+
209
224
  // src/source/file-system.ts
210
225
  var file_system_exports = {};
211
226
  __export(file_system_exports, {
@@ -223,33 +238,50 @@ var Storage = class {
223
238
  this.folders.set("", this.rootFolder);
224
239
  }
225
240
  /**
226
- * Read a file, it doesn't need an extension
227
241
  * @param path - flattened path
228
242
  */
229
- read(path) {
230
- return this.files.get(path);
243
+ read(path2, type) {
244
+ return this.files.get(`${path2}.${type}`);
245
+ }
246
+ /**
247
+ * @param path - flattened path
248
+ */
249
+ readPage(path2) {
250
+ const result = this.read(path2, "page");
251
+ if ((result == null ? void 0 : result.type) !== "page")
252
+ return;
253
+ return result;
254
+ }
255
+ /**
256
+ * @param path - flattened path
257
+ */
258
+ readMeta(path2) {
259
+ const result = this.read(path2, "meta");
260
+ if ((result == null ? void 0 : result.type) !== "meta")
261
+ return;
262
+ return result;
231
263
  }
232
- readDir(path) {
233
- return this.folders.get(path);
264
+ readDir(path2) {
265
+ return this.folders.get(path2);
234
266
  }
235
267
  root() {
236
268
  return this.rootFolder;
237
269
  }
238
- write(path, file) {
270
+ write(path2, file) {
239
271
  var _a;
240
272
  const node = __spreadValues({
241
- file: parseFilePath(path)
273
+ file: parseFilePath(path2)
242
274
  }, file);
243
275
  this.makeDir(node.file.dirname);
244
276
  (_a = this.readDir(node.file.dirname)) == null ? void 0 : _a.children.push(node);
245
- this.files.set(node.file.flattenedPath, node);
277
+ this.files.set(`${node.file.flattenedPath}.${node.type}`, node);
246
278
  }
247
279
  list() {
248
280
  return [...this.files.values()];
249
281
  }
250
- makeDir(path) {
282
+ makeDir(path2) {
251
283
  var _a;
252
- const segments = splitPath(path);
284
+ const segments = splitPath(path2);
253
285
  for (let i = 0; i < segments.length; i++) {
254
286
  const segment = segments.slice(0, i + 1).join("/");
255
287
  if (this.folders.has(segment))
@@ -269,27 +301,28 @@ var Storage = class {
269
301
  function load(options) {
270
302
  const { transformers = [] } = options;
271
303
  const storage = buildStorage(options);
272
- const ctx = {
273
- getSlugs: options.getSlugs,
274
- getUrl: options.getUrl,
275
- storage,
276
- data: {}
277
- };
278
304
  for (const transformer of transformers) {
279
- transformer(ctx);
305
+ transformer({
306
+ storage,
307
+ getUrl: options.getUrl,
308
+ getSlugs: options.getSlugs
309
+ });
280
310
  }
281
- return ctx;
311
+ return { storage };
282
312
  }
283
313
  function buildStorage(options) {
284
314
  const storage = new Storage();
285
315
  for (const file of options.files) {
286
- if (!isRelative(file.path, options.rootDir))
316
+ const relativePath = path.join(
317
+ path.relative(options.rootDir, path.join("./", path.dirname(file.path))),
318
+ path.basename(file.path)
319
+ );
320
+ if (relativePath.startsWith("..") || path.isAbsolute(relativePath))
287
321
  continue;
288
- const path = getRelativePath(file.path, options.rootDir);
289
322
  if (file.type === "page") {
290
- const parsedPath = parseFilePath(path);
323
+ const parsedPath = parseFilePath(relativePath);
291
324
  const slugs = options.getSlugs(parsedPath);
292
- storage.write(path, {
325
+ storage.write(relativePath, {
293
326
  slugs,
294
327
  url: options.getUrl(slugs, parsedPath.locale),
295
328
  type: file.type,
@@ -297,7 +330,7 @@ function buildStorage(options) {
297
330
  });
298
331
  }
299
332
  if (file.type === "meta") {
300
- storage.write(path, {
333
+ storage.write(relativePath, {
301
334
  type: file.type,
302
335
  data: file.data
303
336
  });
@@ -306,26 +339,20 @@ function buildStorage(options) {
306
339
  return storage;
307
340
  }
308
341
 
309
- // src/source/create.ts
310
- function groupByLanguages(nodes, languages) {
342
+ // src/source/loader.ts
343
+ function groupByLanguages(storage, languages) {
311
344
  var _a, _b, _c;
312
- const pageMap = /* @__PURE__ */ new Map();
313
- for (const node of nodes) {
314
- if (node.type === "page")
315
- pageMap.set(node.file.flattenedPath, node);
316
- }
317
345
  const langMap = /* @__PURE__ */ new Map();
318
346
  langMap.set("", []);
319
- for (const lang of languages) {
320
- langMap.set(lang, []);
321
- }
322
- for (const [key, node] of pageMap) {
323
- if (node.file.locale)
347
+ for (const node of storage.list()) {
348
+ if (node.type !== "page" || node.file.locale)
324
349
  continue;
325
350
  (_a = langMap.get("")) == null ? void 0 : _a.push(node);
326
351
  for (const lang of languages) {
327
- const v = (_b = pageMap.get(`${key}.${lang}`)) != null ? _b : node;
328
- (_c = langMap.get(lang)) == null ? void 0 : _c.push(v);
352
+ const list = (_b = langMap.get(lang)) != null ? _b : [];
353
+ const page = (_c = storage.readPage(`${node.file.flattenedPath}.${lang}`)) != null ? _c : node;
354
+ list.push(page);
355
+ langMap.set(lang, list);
329
356
  }
330
357
  }
331
358
  return langMap;
@@ -338,6 +365,10 @@ function createGetUrl(baseUrl) {
338
365
  return joinPaths(paths, "leading");
339
366
  };
340
367
  }
368
+ function getSlugs(info) {
369
+ const result = [...splitPath(info.dirname), info.name];
370
+ return result[result.length - 1] === "index" ? result.slice(0, -1) : result;
371
+ }
341
372
  function loader(options) {
342
373
  return createOutput(options);
343
374
  }
@@ -348,10 +379,7 @@ function createOutput({
348
379
  rootDir = "",
349
380
  transformers,
350
381
  baseUrl = "/",
351
- slugs = (info) => {
352
- const result = [...info.dirname.split("/"), info.name].filter(Boolean);
353
- return result[result.length - 1] === "index" ? result.slice(0, -1) : result;
354
- },
382
+ slugs = getSlugs,
355
383
  url = createGetUrl(baseUrl)
356
384
  }) {
357
385
  const result = load({
@@ -361,7 +389,7 @@ function createOutput({
361
389
  getSlugs: slugs,
362
390
  getUrl: url
363
391
  });
364
- const i18nMap = groupByLanguages(result.storage.list(), languages != null ? languages : []);
392
+ const i18nMap = groupByLanguages(result.storage, languages != null ? languages : []);
365
393
  const builder = createPageTreeBuilder({
366
394
  storage: result.storage,
367
395
  resolveIcon: icon
@@ -376,8 +404,8 @@ function createOutput({
376
404
  },
377
405
  getPage(slugs_ = [], language = "") {
378
406
  var _a;
379
- const path = slugs_.join("/");
380
- return (_a = i18nMap.get(language)) == null ? void 0 : _a.find((page) => page.slugs.join("/") === path);
407
+ const path2 = slugs_.join("/");
408
+ return (_a = i18nMap.get(language)) == null ? void 0 : _a.find((page) => page.slugs.join("/") === path2);
381
409
  }
382
410
  };
383
411
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "9.0.0",
3
+ "version": "10.0.0",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -44,10 +44,6 @@
44
44
  "import": "./dist/link.js",
45
45
  "types": "./dist/link.d.ts"
46
46
  },
47
- "./typescript": {
48
- "import": "./dist/typescript.js",
49
- "types": "./dist/typescript.d.ts"
50
- },
51
47
  "./middleware": {
52
48
  "import": "./dist/middleware.js",
53
49
  "types": "./dist/middleware.d.ts"
@@ -76,9 +72,6 @@
76
72
  "toc": [
77
73
  "./dist/toc.d.ts"
78
74
  ],
79
- "typescript": [
80
- "./dist/typescript.d.ts"
81
- ],
82
75
  "search/client": [
83
76
  "./dist/search/client.d.ts"
84
77
  ],
@@ -116,8 +109,8 @@
116
109
  ],
117
110
  "dependencies": {
118
111
  "@formatjs/intl-localematcher": "^0.5.0",
119
- "@shikijs/rehype": "1.1.5",
120
- "@shikijs/transformers": "1.1.5",
112
+ "@shikijs/rehype": "1.1.7",
113
+ "@shikijs/transformers": "1.1.7",
121
114
  "flexsearch": "0.7.21",
122
115
  "github-slugger": "^2.0.0",
123
116
  "hast-util-to-estree": "^3.1.0",
@@ -127,7 +120,7 @@
127
120
  "remark-gfm": "^4.0.0",
128
121
  "remark-mdx": "^3.0.0",
129
122
  "scroll-into-view-if-needed": "^3.1.0",
130
- "shiki": "1.1.5",
123
+ "shiki": "1.1.7",
131
124
  "swr": "^2.2.2",
132
125
  "unist-util-visit": "^5.0.0"
133
126
  },
@@ -142,7 +135,7 @@
142
135
  "@types/react": "18.2.0",
143
136
  "@types/react-dom": "18.2.1",
144
137
  "algoliasearch": "^4.20.0",
145
- "next": "14.1.0",
138
+ "next": "14.1.1",
146
139
  "unified": "^11.0.4",
147
140
  "eslint-config-custom": "0.0.0",
148
141
  "tsconfig": "0.0.0"
@@ -1,37 +0,0 @@
1
- import * as ts from 'typescript';
2
-
3
- interface DocEntry {
4
- name: string;
5
- description: string;
6
- type: string;
7
- default?: string;
8
- }
9
- interface Context {
10
- program: ts.Program;
11
- checker: ts.TypeChecker;
12
- options: Options;
13
- }
14
- interface EntryContext extends Context {
15
- type: ts.Type;
16
- symbol: ts.Symbol;
17
- }
18
- interface Options {
19
- file: string;
20
- name: string;
21
- /**
22
- * Modify output property entry
23
- */
24
- transform?: (this: EntryContext, entry: DocEntry, propertyType: ts.Type, propertySymbol: ts.Symbol) => void;
25
- options?: Partial<{
26
- files: string[];
27
- tsconfigPath: string;
28
- /** A root directory to resolve relative path entries in the config file to. e.g. outDir */
29
- basePath: string;
30
- }>;
31
- }
32
- /**
33
- * Generate documentation for properties in an exported type/interface
34
- */
35
- declare function generateDocumentation(options: Options): DocEntry[];
36
-
37
- export { type DocEntry, type Options, generateDocumentation };
@@ -1,90 +0,0 @@
1
- import {
2
- __spreadProps,
3
- __spreadValues
4
- } from "./chunk-WEAGW6MQ.js";
5
-
6
- // src/typescript.ts
7
- import * as ts from "typescript";
8
- var cache = /* @__PURE__ */ new Map();
9
- function getProgram(options = {}) {
10
- var _a, _b, _c;
11
- const key = JSON.stringify(options);
12
- const cached = cache.get(key);
13
- if (cached)
14
- return cached;
15
- const configFile = ts.readJsonConfigFile(
16
- (_a = options.tsconfigPath) != null ? _a : "./tsconfig.json",
17
- (path) => ts.sys.readFile(path)
18
- );
19
- const parsed = ts.parseJsonSourceFileConfigFileContent(
20
- configFile,
21
- ts.sys,
22
- (_b = options.basePath) != null ? _b : "./"
23
- );
24
- const program = ts.createProgram({
25
- rootNames: (_c = options.files) != null ? _c : parsed.fileNames,
26
- options: __spreadProps(__spreadValues({}, parsed.options), {
27
- incremental: false
28
- })
29
- });
30
- cache.set(key, program);
31
- return program;
32
- }
33
- function getExportedSymbol({
34
- options: { file, name },
35
- checker,
36
- program
37
- }) {
38
- const sourceFile = program.getSourceFile(file);
39
- if (!sourceFile)
40
- return;
41
- const fileSymbol = checker.getSymbolAtLocation(sourceFile);
42
- if (!fileSymbol)
43
- return;
44
- const exports = checker.getExportsOfModule(fileSymbol);
45
- return exports.find((e) => e.getEscapedName().toString() === name);
46
- }
47
- function generateDocumentation(options) {
48
- const program = getProgram(options.options);
49
- const checker = program.getTypeChecker();
50
- const ctx = {
51
- checker,
52
- program,
53
- options
54
- };
55
- const symbol = getExportedSymbol(ctx);
56
- if (!symbol)
57
- return [];
58
- const type = checker.getDeclaredTypeOfSymbol(symbol);
59
- const entryContext = __spreadProps(__spreadValues({}, ctx), {
60
- type,
61
- symbol
62
- });
63
- return type.getProperties().map(getDocEntry.bind(entryContext));
64
- }
65
- function getDocEntry(prop) {
66
- var _a;
67
- const subType = this.checker.getTypeOfSymbol(prop);
68
- const defaultJsDocTag = prop.getJsDocTags().find((info) => ["default", "defaultValue"].includes(info.name));
69
- let typeName = this.checker.typeToString(
70
- subType.getNonNullableType(),
71
- void 0,
72
- ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope
73
- );
74
- if (subType.aliasSymbol && !subType.aliasTypeArguments) {
75
- typeName = subType.aliasSymbol.escapedName.toString();
76
- }
77
- const entry = {
78
- name: prop.getName(),
79
- description: ts.displayPartsToString(
80
- prop.getDocumentationComment(this.checker)
81
- ),
82
- default: (defaultJsDocTag == null ? void 0 : defaultJsDocTag.text) ? ts.displayPartsToString(defaultJsDocTag.text) : void 0,
83
- type: typeName
84
- };
85
- (_a = this.options.transform) == null ? void 0 : _a.call(this, entry, subType, prop);
86
- return entry;
87
- }
88
- export {
89
- generateDocumentation
90
- };