fumadocs-core 16.17.4 → 16.17.5

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,3 @@
1
- import { r as findPath } from "./utils-DEVq3cEC.js";
2
1
  import { r as extname, t as basename } from "./path-m9Srg2Jq.js";
3
2
  //#region src/search/server/build-index.ts
4
3
  async function buildIndexDefault(page) {
@@ -29,19 +28,27 @@ async function buildDocuments(source, map) {
29
28
  function isBreadcrumbItem(item) {
30
29
  return typeof item === "string" && item.length > 0;
31
30
  }
32
- function buildBreadcrumbs(source, page) {
33
- const pageTree = source.getPageTree(page.locale);
34
- const path = findPath(pageTree.children, (node) => node.type === "page" && node.url === page.url);
35
- if (path) {
36
- const breadcrumbs = [];
37
- path.pop();
38
- if (isBreadcrumbItem(pageTree.name)) breadcrumbs.push(pageTree.name);
39
- for (const segment of path) {
40
- if (!isBreadcrumbItem(segment.name)) continue;
41
- breadcrumbs.push(segment.name);
42
- }
43
- return breadcrumbs;
44
- }
31
+ /**
32
+ * Get the breadcrumbs of pages, each page tree is walked once.
33
+ */
34
+ function createBreadcrumbs(source) {
35
+ const trees = /* @__PURE__ */ new Map();
36
+ return (page) => {
37
+ const tree = source.getPageTree(page.locale);
38
+ let breadcrumbs = trees.get(tree);
39
+ if (!breadcrumbs) trees.set(tree, breadcrumbs = collectBreadcrumbs(tree, [], /* @__PURE__ */ new Map()));
40
+ return breadcrumbs.get(page.url);
41
+ };
42
+ }
43
+ /** like `findPath()`, a page takes its first path, with the separator above it */
44
+ function collectBreadcrumbs(folder, parents, out) {
45
+ const path = isBreadcrumbItem(folder.name) ? [...parents, folder.name] : parents;
46
+ if (folder.type === "folder" && folder.index && !out.has(folder.index.url)) out.set(folder.index.url, path);
47
+ let current = path;
48
+ for (const node of folder.children) if (node.type === "separator") current = isBreadcrumbItem(node.name) ? [...path, node.name] : path;
49
+ else if (node.type === "folder") collectBreadcrumbs(node, current, out);
50
+ else if (!out.has(node.url)) out.set(node.url, current);
51
+ return out;
45
52
  }
46
53
  //#endregion
47
- export { buildDocuments as n, buildIndexDefault as r, buildBreadcrumbs as t };
54
+ export { buildIndexDefault as n, createBreadcrumbs as r, buildDocuments as t };
@@ -1,4 +1,4 @@
1
- import { n as buildDocuments } from "../build-index-BD-VRKOW.js";
1
+ import { t as buildDocuments } from "../build-index-Bxu0jldy.js";
2
2
  //#region src/search/algolia.ts
3
3
  /**
4
4
  * Build the search indexes of every page in a source.
@@ -1,4 +1,4 @@
1
- import { r as buildIndexDefault, t as buildBreadcrumbs } from "../build-index-BD-VRKOW.js";
1
+ import { n as buildIndexDefault, r as createBreadcrumbs } from "../build-index-Bxu0jldy.js";
2
2
  import { t as createEndpoint } from "../endpoint-MyoBU5IC.js";
3
3
  import { t as buildDocuments } from "../build-doc-C7HYXyRK.js";
4
4
  import { n as search, t as createDocument } from "../utils-CbSdov6X.js";
@@ -89,12 +89,13 @@ function flexsearchFromSource(loader, options = {}) {
89
89
  const cache = /* @__PURE__ */ new WeakMap();
90
90
  const { buildIndex = buildIndexDefault, ...rest } = options;
91
91
  async function initServer(loader) {
92
+ const getBreadcrumbs = createBreadcrumbs(loader);
92
93
  const indexes = await Promise.all(loader.getPages().map(async (page) => {
93
94
  const index = await buildIndex(page);
94
95
  return {
95
96
  ...index,
96
97
  locale: page.locale,
97
- breadcrumbs: index.breadcrumbs ?? buildBreadcrumbs(loader, page)
98
+ breadcrumbs: index.breadcrumbs ?? getBreadcrumbs(page)
98
99
  };
99
100
  }));
100
101
  if (loader._i18n) return serverI18n({
@@ -1,14 +1,15 @@
1
- import { n as buildDocuments, t as buildBreadcrumbs } from "../build-index-BD-VRKOW.js";
1
+ import { r as createBreadcrumbs, t as buildDocuments } from "../build-index-Bxu0jldy.js";
2
2
  //#region src/search/meilisearch.ts
3
3
  /**
4
4
  * Build the search documents of every page in a source.
5
5
  */
6
6
  async function toDocuments(source, options = {}) {
7
7
  const loader = typeof source === "function" ? await source() : source;
8
+ const getBreadcrumbs = createBreadcrumbs(loader);
8
9
  return buildDocuments(loader, (index, page) => ({
9
10
  title: index.title,
10
11
  description: index.description,
11
- breadcrumbs: buildBreadcrumbs(loader, page),
12
+ breadcrumbs: getBreadcrumbs(page),
12
13
  url: index.url,
13
14
  structured: index.structuredData,
14
15
  tag: options.tag?.(page),
@@ -1,4 +1,4 @@
1
- import { n as buildDocuments } from "../build-index-BD-VRKOW.js";
1
+ import { t as buildDocuments } from "../build-index-Bxu0jldy.js";
2
2
  //#region src/search/orama-cloud.ts
3
3
  /**
4
4
  * Build the search indexes of every page in a source.
@@ -1,4 +1,4 @@
1
- import { r as buildIndexDefault, t as buildBreadcrumbs } from "../build-index-BD-VRKOW.js";
1
+ import { n as buildIndexDefault, r as createBreadcrumbs } from "../build-index-Bxu0jldy.js";
2
2
  import { n as searchSimple, t as searchAdvanced } from "../advanced-cJMxLDd5.js";
3
3
  import { n as defaultReadOptions, t as createEndpoint } from "../endpoint-MyoBU5IC.js";
4
4
  import { t as buildDocuments } from "../build-doc-C7HYXyRK.js";
@@ -186,11 +186,12 @@ function createFromSource(loader, options = {}) {
186
186
  const { buildIndex = buildIndexDefault } = options;
187
187
  const cache = /* @__PURE__ */ new WeakMap();
188
188
  async function initServer(loader) {
189
+ const getBreadcrumbs = createBreadcrumbs(loader);
189
190
  const indexes = await Promise.all(loader.getPages().map(async (page) => {
190
191
  const index = await buildIndex(page);
191
192
  return {
192
193
  ...index,
193
- breadcrumbs: index.breadcrumbs ?? buildBreadcrumbs(loader, page),
194
+ breadcrumbs: index.breadcrumbs ?? getBreadcrumbs(page),
194
195
  locale: page.locale
195
196
  };
196
197
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "16.17.4",
3
+ "version": "16.17.5",
4
4
  "description": "The React.js library for building a documentation website",
5
5
  "keywords": [
6
6
  "Docs",