fumadocs-core 12.4.1 → 12.5.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.
@@ -5,7 +5,17 @@ interface BreadcrumbItem {
5
5
  name: ReactNode;
6
6
  url?: string;
7
7
  }
8
- interface BreadcrumbOptions {
8
+ interface BreadcrumbOptions extends SearchOptions {
9
+ /**
10
+ * Include the root itself in the breadcrumb items array
11
+ *
12
+ * @defaultValue false
13
+ */
14
+ includeRoot?: boolean;
15
+ }
16
+ declare function useBreadcrumb(url: string, tree: Root, options?: BreadcrumbOptions): BreadcrumbItem[];
17
+ declare function getBreadcrumbItems(url: string, tree: Root, options?: BreadcrumbOptions): BreadcrumbItem[];
18
+ interface SearchOptions {
9
19
  /**
10
20
  * Include the page itself in the breadcrumb items array
11
21
  *
@@ -19,7 +29,5 @@ interface BreadcrumbOptions {
19
29
  */
20
30
  includeSeparator?: boolean;
21
31
  }
22
- declare function useBreadcrumb(url: string, tree: Root, options?: BreadcrumbOptions): BreadcrumbItem[];
23
- declare function getBreadcrumbItems(url: string, tree: Root, options?: BreadcrumbOptions): BreadcrumbItem[];
24
32
 
25
33
  export { type BreadcrumbItem, type BreadcrumbOptions, getBreadcrumbItems, useBreadcrumb };
@@ -1,26 +1,33 @@
1
- import "./chunk-CWMXXUWU.js";
1
+ import {
2
+ __objRest
3
+ } from "./chunk-CWMXXUWU.js";
2
4
 
3
5
  // src/breadcrumb.tsx
4
6
  import { useMemo } from "react";
5
- function useBreadcrumb(url, tree, options = {}) {
7
+ function useBreadcrumb(url, tree, options) {
6
8
  return useMemo(
7
9
  () => getBreadcrumbItems(url, tree, options),
8
10
  [tree, url, options]
9
11
  );
10
12
  }
11
13
  function getBreadcrumbItems(url, tree, options = {}) {
12
- var _a, _b, _c;
13
- return (_c = searchPath(tree.children, url, {
14
- includePage: (_a = options.includePage) != null ? _a : true,
15
- includeSeparator: (_b = options.includeSeparator) != null ? _b : false
16
- })) != null ? _c : [];
14
+ var _b, _c;
15
+ const _a = options, { includeRoot } = _a, rest = __objRest(_a, ["includeRoot"]);
16
+ const path = (_b = searchPath(tree.children, url, rest)) != null ? _b : [];
17
+ if (includeRoot) {
18
+ path.unshift({
19
+ name: tree.name,
20
+ url: (_c = tree.children.find((p) => p.type === "page")) == null ? void 0 : _c.url
21
+ });
22
+ }
23
+ return path;
17
24
  }
18
25
  function searchPath(nodes, url, options) {
19
26
  var _a, _b;
27
+ const { includePage = true, includeSeparator = false } = options;
20
28
  let separator;
21
29
  for (const node of nodes) {
22
- if (options.includeSeparator && node.type === "separator")
23
- separator = node.name;
30
+ if (includeSeparator && node.type === "separator") separator = node.name;
24
31
  if (node.type === "folder") {
25
32
  if (((_a = node.index) == null ? void 0 : _a.url) === url) {
26
33
  const items2 = [];
@@ -45,7 +52,7 @@ function searchPath(nodes, url, options) {
45
52
  if (node.type === "page" && node.url === url) {
46
53
  const items = [];
47
54
  if (separator) items.push({ name: separator });
48
- if (options.includePage)
55
+ if (includePage)
49
56
  items.push({
50
57
  name: node.name,
51
58
  url: node.url
@@ -22,7 +22,9 @@ interface SimpleOptions {
22
22
  interface AdvancedOptions {
23
23
  indexes: AdvancedIndex[] | Dynamic<AdvancedIndex>;
24
24
  /**
25
- * Enabled custom tags
25
+ * Enable search tags for filtering results
26
+ *
27
+ * @defaultValue false
26
28
  */
27
29
  tag?: boolean;
28
30
  language?: string;
@@ -47,6 +49,7 @@ declare function initSearchAPI({ indexes, language }: SimpleOptions): SearchAPI;
47
49
  interface AdvancedIndex {
48
50
  id: string;
49
51
  title: string;
52
+ keywords?: string;
50
53
  /**
51
54
  * Required if `tag` is enabled
52
55
  */
@@ -117,25 +117,30 @@ function initSearchAPIAdvanced({
117
117
  language,
118
118
  tag = false
119
119
  }) {
120
- const store = ["id", "url", "content", "page_id", "type"];
120
+ const store = ["id", "url", "content", "page_id", "type", "keywords"];
121
121
  function getDocument() {
122
122
  return __async(this, null, function* () {
123
123
  const items = typeof indexes === "function" ? yield indexes() : indexes;
124
124
  const index = new Document({
125
125
  language,
126
126
  cache: 100,
127
- tokenize: "forward",
128
127
  optimize: true,
129
- context: {
130
- depth: 2,
131
- bidirectional: true,
132
- resolution: 9
133
- },
134
128
  document: {
135
129
  id: "id",
136
130
  tag: tag ? "tag" : void 0,
137
131
  store,
138
- index: ["content"]
132
+ index: [
133
+ {
134
+ field: "content",
135
+ tokenize: "forward",
136
+ context: { depth: 2, bidirectional: true, resolution: 9 }
137
+ },
138
+ {
139
+ field: "keywords",
140
+ tokenize: "strict",
141
+ resolution: 9
142
+ }
143
+ ]
139
144
  }
140
145
  });
141
146
  for (const page of items) {
@@ -146,6 +151,7 @@ function initSearchAPIAdvanced({
146
151
  page_id: page.id,
147
152
  type: "page",
148
153
  content: page.title,
154
+ keywords: page.keywords,
149
155
  tag: page.tag,
150
156
  url: page.url
151
157
  });
@@ -185,8 +191,8 @@ function initSearchAPIAdvanced({
185
191
  const map = /* @__PURE__ */ new Map();
186
192
  for (const item of (_b = (_a = results[0]) == null ? void 0 : _a.result) != null ? _b : []) {
187
193
  if (item.doc.type === "page") {
188
- if (!map.has(item.doc.page_id)) {
189
- map.set(item.doc.page_id, []);
194
+ if (!map.has(item.doc.id)) {
195
+ map.set(item.doc.id, []);
190
196
  }
191
197
  continue;
192
198
  }
@@ -11,6 +11,8 @@ import 'unified';
11
11
  interface Options extends SearchOptions {
12
12
  /**
13
13
  * Use `empty` as result if query is empty
14
+ *
15
+ * @defaultValue true
14
16
  */
15
17
  allowEmpty?: boolean;
16
18
  }
@@ -14,32 +14,54 @@ interface DocumentRecord {
14
14
  */
15
15
  url: string;
16
16
  structured: StructuredData;
17
+ /**
18
+ * Tag to filter results
19
+ */
20
+ tag?: string;
17
21
  /**
18
22
  * Data to be added to each section index
19
23
  */
20
24
  extra_data?: object;
21
25
  }
22
26
  interface SyncOptions {
27
+ /**
28
+ * Index Name for documents
29
+ */
23
30
  document?: string;
31
+ /**
32
+ * Search indexes
33
+ */
24
34
  documents: DocumentRecord[];
25
35
  }
26
- declare function sync(client: SearchClient, { document, documents }: SyncOptions): Promise<void>;
36
+ /**
37
+ * Update index settings and replace all objects
38
+ *
39
+ * @param client - Algolia Admin Client
40
+ * @param options - Index Options
41
+ */
42
+ declare function sync(client: SearchClient, options: SyncOptions): Promise<void>;
27
43
  declare function setIndexSettings(index: SearchIndex): Promise<void>;
28
- declare function updateDocuments(index: SearchIndex, documents: DocumentRecord[]): Promise<void>;
29
- interface BaseIndex {
30
- objectID: string;
31
- title: string;
32
- url: string;
44
+ interface Section {
45
+ /**
46
+ * Heading content
47
+ */
33
48
  section?: string;
34
49
  /**
35
50
  * The anchor id
36
51
  */
37
52
  section_id?: string;
53
+ content: string;
54
+ }
55
+ declare function updateDocuments(index: SearchIndex, documents: DocumentRecord[]): Promise<void>;
56
+ interface BaseIndex extends Section {
57
+ objectID: string;
58
+ title: string;
59
+ url: string;
60
+ tag?: string;
38
61
  /**
39
62
  * The id of page, used for distinct
40
63
  */
41
64
  page_id: string;
42
- content: string;
43
65
  }
44
66
 
45
67
  export { type BaseIndex, type SyncOptions, setIndexSettings, sync, updateDocuments };
@@ -4,9 +4,9 @@ import {
4
4
  } from "../chunk-CWMXXUWU.js";
5
5
 
6
6
  // src/search-algolia/server.ts
7
- import { randomUUID } from "crypto";
8
- function sync(_0, _1) {
9
- return __async(this, arguments, function* (client, { document = "document", documents }) {
7
+ function sync(client, options) {
8
+ return __async(this, null, function* () {
9
+ const { document = "document", documents } = options;
10
10
  const index = client.initIndex(document);
11
11
  yield setIndexSettings(index);
12
12
  yield updateDocuments(index, documents);
@@ -50,11 +50,12 @@ function updateDocuments(index, documents) {
50
50
  return __async(this, null, function* () {
51
51
  const objects = documents.flatMap((page) => {
52
52
  return getSections(page).map(
53
- (section) => __spreadValues(__spreadValues({
54
- objectID: `${page._id}-${randomUUID()}`,
53
+ (section, idx) => __spreadValues(__spreadValues({
54
+ objectID: `${page._id}-${idx.toString()}`,
55
55
  title: page.title,
56
56
  url: page.url,
57
- page_id: page._id
57
+ page_id: page._id,
58
+ tag: page.tag
58
59
  }, section), page.extra_data)
59
60
  );
60
61
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "12.4.1",
3
+ "version": "12.5.0",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -120,8 +120,8 @@
120
120
  ],
121
121
  "dependencies": {
122
122
  "@formatjs/intl-localematcher": "^0.5.4",
123
- "@shikijs/rehype": "^1.10.1",
124
- "@shikijs/transformers": "^1.10.1",
123
+ "@shikijs/rehype": "^1.10.3",
124
+ "@shikijs/transformers": "^1.10.3",
125
125
  "flexsearch": "0.7.21",
126
126
  "github-slugger": "^2.0.0",
127
127
  "negotiator": "^0.6.3",
@@ -131,7 +131,7 @@
131
131
  "remark-gfm": "^4.0.0",
132
132
  "remark-mdx": "^3.0.1",
133
133
  "scroll-into-view-if-needed": "^3.1.0",
134
- "shiki": "^1.10.1",
134
+ "shiki": "^1.10.3",
135
135
  "swr": "^2.2.5",
136
136
  "unist-util-visit": "^5.0.0"
137
137
  },
@@ -143,11 +143,11 @@
143
143
  "@types/hast": "^3.0.4",
144
144
  "@types/mdast": "^4.0.3",
145
145
  "@types/negotiator": "^0.6.3",
146
- "@types/node": "20.14.9",
146
+ "@types/node": "20.14.10",
147
147
  "@types/react": "^18.3.3",
148
148
  "@types/react-dom": "^18.3.0",
149
149
  "algoliasearch": "^4.24.0",
150
- "next": "^14.2.4",
150
+ "next": "^14.2.5",
151
151
  "unified": "^11.0.5",
152
152
  "eslint-config-custom": "0.0.0",
153
153
  "tsconfig": "0.0.0"