fumadocs-core 13.0.2 → 13.0.4

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.
@@ -41,6 +41,7 @@ declare function createSearchAPI<T extends 'simple' | 'advanced'>(type: T, optio
41
41
  declare function createI18nSearchAPI<T extends 'simple' | 'advanced'>(type: T, options: T extends 'simple' ? ToI18n<SimpleOptions> : ToI18n<AdvancedOptions>): SearchAPI;
42
42
  interface Index {
43
43
  title: string;
44
+ description?: string;
44
45
  content: string;
45
46
  url: string;
46
47
  keywords?: string;
@@ -49,9 +50,10 @@ declare function initSearchAPI({ indexes, language }: SimpleOptions): SearchAPI;
49
50
  interface AdvancedIndex {
50
51
  id: string;
51
52
  title: string;
53
+ description?: string;
52
54
  keywords?: string;
53
55
  /**
54
- * Required if `tag` is enabled
56
+ * Required if tag filter is enabled
55
57
  */
56
58
  tag?: string;
57
59
  /**
@@ -63,6 +63,14 @@ function initSearchAPI({ indexes, language }) {
63
63
  tokenize: "forward",
64
64
  resolution: 9
65
65
  },
66
+ {
67
+ field: "description",
68
+ tokenize: "strict",
69
+ context: {
70
+ depth: 1,
71
+ resolution: 9
72
+ }
73
+ },
66
74
  {
67
75
  field: "content",
68
76
  tokenize: "strict",
@@ -82,6 +90,7 @@ function initSearchAPI({ indexes, language }) {
82
90
  for (const page of items) {
83
91
  index.add({
84
92
  title: page.title,
93
+ description: page.description,
85
94
  url: page.url,
86
95
  content: page.content,
87
96
  keywords: page.keywords
@@ -146,6 +155,16 @@ function initSearchAPIAdvanced({
146
155
  tag: page.tag,
147
156
  url: page.url
148
157
  });
158
+ if (page.description) {
159
+ index.add({
160
+ id: page.id + (id++).toString(),
161
+ page_id: page.id,
162
+ tag: page.tag,
163
+ type: "text",
164
+ url: page.url,
165
+ content: page.description
166
+ });
167
+ }
149
168
  for (const heading of data.headings) {
150
169
  index.add({
151
170
  id: page.id + (id++).toString(),
@@ -9,6 +9,7 @@ interface DocumentRecord {
9
9
  */
10
10
  _id: string;
11
11
  title: string;
12
+ description?: string;
12
13
  /**
13
14
  * URL to the page
14
15
  */
@@ -41,19 +42,8 @@ interface SyncOptions {
41
42
  */
42
43
  declare function sync(client: SearchClient, options: SyncOptions): Promise<void>;
43
44
  declare function setIndexSettings(index: SearchIndex): Promise<void>;
44
- interface Section {
45
- /**
46
- * Heading content
47
- */
48
- section?: string;
49
- /**
50
- * The anchor id
51
- */
52
- section_id?: string;
53
- content: string;
54
- }
55
45
  declare function updateDocuments(index: SearchIndex, documents: DocumentRecord[]): Promise<void>;
56
- interface BaseIndex extends Section {
46
+ interface BaseIndex {
57
47
  objectID: string;
58
48
  title: string;
59
49
  url: string;
@@ -62,6 +52,15 @@ interface BaseIndex extends Section {
62
52
  * The id of page, used for distinct
63
53
  */
64
54
  page_id: string;
55
+ /**
56
+ * Heading content
57
+ */
58
+ section?: string;
59
+ /**
60
+ * Heading (anchor) id
61
+ */
62
+ section_id?: string;
63
+ content: string;
65
64
  }
66
65
 
67
66
  export { type BaseIndex, type SyncOptions, setIndexSettings, sync, updateDocuments };
@@ -16,43 +16,38 @@ async function setIndexSettings(index) {
16
16
  attributesForFaceting: ["tag"]
17
17
  });
18
18
  }
19
- function getSections(page) {
19
+ function toIndex(page) {
20
+ let id = 0;
21
+ const indexes = [];
20
22
  const scannedHeadings = /* @__PURE__ */ new Set();
21
- return page.structured.contents.flatMap((p) => {
22
- const heading = p.heading ? page.structured.headings.find((h) => p.heading === h.id) : null;
23
- const section = {
24
- section: heading?.content,
25
- section_id: heading?.id,
26
- content: p.content
23
+ function createIndex(section, sectionId, content) {
24
+ return {
25
+ objectID: `${page._id}-${(id++).toString()}`,
26
+ title: page.title,
27
+ url: page.url,
28
+ page_id: page._id,
29
+ tag: page.tag,
30
+ section,
31
+ section_id: sectionId,
32
+ content,
33
+ ...page.extra_data
27
34
  };
35
+ }
36
+ if (page.description)
37
+ indexes.push(createIndex(void 0, void 0, page.description));
38
+ page.structured.contents.forEach((p) => {
39
+ const heading = p.heading ? page.structured.headings.find((h) => p.heading === h.id) : null;
40
+ const index = createIndex(heading?.content, heading?.id, p.content);
28
41
  if (heading && !scannedHeadings.has(heading.id)) {
29
42
  scannedHeadings.add(heading.id);
30
- return [
31
- {
32
- section: heading.content,
33
- section_id: heading.id,
34
- content: heading.content
35
- },
36
- section
37
- ];
43
+ indexes.push(createIndex(heading.content, heading.id, heading.content));
38
44
  }
39
- return section;
45
+ indexes.push(index);
40
46
  });
47
+ return indexes;
41
48
  }
42
49
  async function updateDocuments(index, documents) {
43
- const objects = documents.flatMap((page) => {
44
- return getSections(page).map(
45
- (section, idx) => ({
46
- objectID: `${page._id}-${idx.toString()}`,
47
- title: page.title,
48
- url: page.url,
49
- page_id: page._id,
50
- tag: page.tag,
51
- ...section,
52
- ...page.extra_data
53
- })
54
- );
55
- });
50
+ const objects = documents.flatMap(toIndex);
56
51
  await index.replaceAllObjects(objects);
57
52
  }
58
53
  export {
@@ -20,45 +20,6 @@ interface FileInfo {
20
20
  declare function parseFilePath(path: string): FileInfo;
21
21
  declare function parseFolderPath(path: string): FileInfo;
22
22
 
23
- interface File {
24
- file: FileInfo;
25
- format: 'meta' | 'page';
26
- data: Record<string, unknown>;
27
- }
28
- interface Folder {
29
- file: FileInfo;
30
- children: (File | Folder)[];
31
- }
32
- /**
33
- * A virtual file system that solves inconsistent behaviours
34
- *
35
- * Some source providers may not provide the full file structure, this will cause inconsistent outputs for page builder and other transformers
36
- */
37
- declare class Storage {
38
- files: Map<string, File>;
39
- folders: Map<string, Folder>;
40
- private rootFolder;
41
- constructor();
42
- /**
43
- * @param path - flattened path
44
- * @param format - file format
45
- */
46
- read(path: string, format: string): File | undefined;
47
- readDir(path: string): Folder | undefined;
48
- root(): Folder;
49
- write(path: string, format: 'meta' | 'page', data: Record<string, unknown>): void;
50
- list(): File[];
51
- makeDir(path: string): void;
52
- }
53
-
54
- type fileSystem_File = File;
55
- type fileSystem_Folder = Folder;
56
- type fileSystem_Storage = Storage;
57
- declare const fileSystem_Storage: typeof Storage;
58
- declare namespace fileSystem {
59
- export { type fileSystem_File as File, type fileSystem_Folder as Folder, fileSystem_Storage as Storage };
60
- }
61
-
62
23
  interface LoadOptions {
63
24
  transformers?: Transformer[];
64
25
  rootDir?: string;
@@ -168,18 +129,62 @@ type InferMetaType<Utils extends LoaderOutput<any>> = Utils extends LoaderOutput
168
129
  * @internal
169
130
  */
170
131
  type UrlFn = (slugs: string[], locale?: string) => string;
171
- /**
172
- * @internal
173
- */
174
- interface FileData {
175
- meta: {
132
+
133
+ interface MetaFile {
134
+ file: FileInfo;
135
+ format: 'meta';
136
+ data: {
176
137
  data: MetaData;
177
138
  };
178
- file: {
139
+ }
140
+ interface PageFile {
141
+ file: FileInfo;
142
+ format: 'page';
143
+ data: {
179
144
  slugs: string[];
180
145
  data: PageData;
181
146
  };
182
147
  }
148
+ type File = MetaFile | PageFile;
149
+ interface Folder {
150
+ file: FileInfo;
151
+ children: (File | Folder)[];
152
+ }
153
+ /**
154
+ * A virtual file system that solves inconsistent behaviours
155
+ *
156
+ * Some source providers may not provide the full file structure, this will cause inconsistent outputs for page builder and other transformers
157
+ */
158
+ declare class Storage {
159
+ files: Map<string, File>;
160
+ folders: Map<string, Folder>;
161
+ private rootFolder;
162
+ constructor();
163
+ /**
164
+ * @param path - flattened path
165
+ * @param format - file format
166
+ */
167
+ read<F extends File['format']>(path: string, format: F): Extract<File, {
168
+ format: F;
169
+ }> | undefined;
170
+ readDir(path: string): Folder | undefined;
171
+ root(): Folder;
172
+ write<F extends File['format']>(path: string, format: F, data: Extract<File, {
173
+ format: F;
174
+ }>['data']): void;
175
+ list(): File[];
176
+ makeDir(path: string): void;
177
+ }
178
+
179
+ type fileSystem_File = File;
180
+ type fileSystem_Folder = Folder;
181
+ type fileSystem_MetaFile = MetaFile;
182
+ type fileSystem_PageFile = PageFile;
183
+ type fileSystem_Storage = Storage;
184
+ declare const fileSystem_Storage: typeof Storage;
185
+ declare namespace fileSystem {
186
+ export { type fileSystem_File as File, type fileSystem_Folder as Folder, type fileSystem_MetaFile as MetaFile, type fileSystem_PageFile as PageFile, fileSystem_Storage as Storage };
187
+ }
183
188
 
184
189
  interface BuildPageTreeOptions {
185
190
  /**
@@ -188,8 +193,8 @@ interface BuildPageTreeOptions {
188
193
  * @defaultValue false
189
194
  */
190
195
  attachFolderIds?: boolean;
191
- attachFile?: (node: Item, file?: File) => Item;
192
- attachFolder?: (node: Folder$1, folder: Folder, meta?: File) => Folder$1;
196
+ attachFile?: (node: Item, file?: PageFile) => Item;
197
+ attachFolder?: (node: Folder$1, folder: Folder, meta?: MetaFile) => Folder$1;
193
198
  attachSeparator?: (node: Separator) => Separator;
194
199
  storage: Storage;
195
200
  getUrl: UrlFn;
@@ -214,4 +219,4 @@ interface PageTreeBuilder {
214
219
  }
215
220
  declare function createPageTreeBuilder(): PageTreeBuilder;
216
221
 
217
- export { type BuildPageTreeOptions, type BuildPageTreeOptionsWithI18n, type FileData, type FileInfo, fileSystem as FileSystem, type InferMetaType, type InferPageType, type LanguageEntry, type LoadOptions, type LoaderConfig, type LoaderOptions, type LoaderOutput, type Meta, type MetaData, type Page, type PageData, type PageTreeBuilder, type Source, type SourceConfig, type Transformer, type UrlFn, type VirtualFile, createGetUrl, createPageTreeBuilder, getSlugs, loadFiles, loader, parseFilePath, parseFolderPath };
222
+ export { type BuildPageTreeOptions, type BuildPageTreeOptionsWithI18n, type FileInfo, fileSystem as FileSystem, type InferMetaType, type InferPageType, type LanguageEntry, type LoadOptions, type LoaderConfig, type LoaderOptions, type LoaderOutput, type Meta, type MetaData, type Page, type PageData, type PageTreeBuilder, type Source, type SourceConfig, type Transformer, type UrlFn, type VirtualFile, createGetUrl, createPageTreeBuilder, getSlugs, loadFiles, loader, parseFilePath, parseFolderPath };
@@ -172,12 +172,11 @@ function buildFolderNode(folder, isGlobalRoot, ctx) {
172
172
  }
173
173
  function buildFileNode(file, ctx) {
174
174
  const localized = findLocalizedFile(file.file.flattenedPath, "page", ctx) ?? file;
175
- const data = localized.data;
176
175
  const item = {
177
176
  type: "page",
178
- name: data.data.title,
179
- icon: ctx.options.resolveIcon?.(data.data.icon),
180
- url: ctx.options.getUrl(data.slugs, ctx.lang)
177
+ name: localized.data.data.title,
178
+ icon: ctx.options.resolveIcon?.(localized.data.data.icon),
179
+ url: ctx.options.getUrl(localized.data.slugs, ctx.lang)
181
180
  };
182
181
  return removeUndefined(ctx.options.attachFile?.(item, file) ?? item);
183
182
  }
@@ -418,12 +417,11 @@ function createOutput({
418
417
  };
419
418
  }
420
419
  function fileToPage(file, getUrl, locale) {
421
- const data = file.data;
422
420
  return {
423
421
  file: file.file,
424
- url: getUrl(data.slugs, locale),
425
- slugs: data.slugs,
426
- data: data.data
422
+ url: getUrl(file.data.slugs, locale),
423
+ slugs: file.data.slugs,
424
+ data: file.data.data
427
425
  };
428
426
  }
429
427
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "13.0.2",
3
+ "version": "13.0.4",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",