fumadocs-core 16.14.4 → 16.14.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.
@@ -109,13 +109,23 @@ interface PageTreeBuilder {
109
109
  //#endregion
110
110
  //#region src/source/plugins/slugs.d.ts
111
111
  /**
112
- * a function to generate slugs, return `undefined` to fallback to default generation.
112
+ * a function to generate slugs, return `undefined` to generate default slugs.
113
+ *
114
+ * conflicting cases like `dir/index.mdx` vs `dir.mdx` are resolved after the function returns.
115
+ *
116
+ * @param next - generate the default slugs from file path (before conflict resolution).
113
117
  */
114
- type SlugFn<S extends ContentStorage = ContentStorage> = (file: S['$inferPage']) => string[] | undefined;
118
+ type SlugFn<S extends ContentStorage = ContentStorage> = (file: S['$inferPage'], next: () => string[]) => string[] | undefined;
119
+ interface SlugsPluginOptions<S extends ContentStorage = ContentStorage> {
120
+ /** Slugs to prepend to every page. */
121
+ baseSlugs?: string[];
122
+ /** generate default slugs for pages */
123
+ slugs?: SlugFn<S>;
124
+ }
115
125
  /**
116
- * Generate slugs for pages if missing
126
+ * Generate slugs for pages if missing.
117
127
  */
118
- declare function slugsPlugin(slugFn?: SlugFn): LoaderPlugin;
128
+ declare function slugsPlugin(optsOrFn?: SlugsPluginOptions | SlugFn): LoaderPlugin;
119
129
  /**
120
130
  * Generate slugs from file data (e.g. frontmatter).
121
131
  *
@@ -146,7 +156,7 @@ interface LoaderConfig {
146
156
  meta: Meta;
147
157
  i18n: I18nConfig | undefined;
148
158
  }
149
- interface LoaderOptions<S extends ContentStorage = ContentStorage, I18n extends I18nConfig | undefined = I18nConfig | undefined> {
159
+ interface LoaderOptions<S extends ContentStorage = ContentStorage, I18n extends I18nConfig | undefined = I18nConfig | undefined> extends SlugsPluginOptions<S> {
150
160
  baseUrl: string;
151
161
  i18n?: I18n;
152
162
  url?: (slugs: string[], locale?: string) => string;
@@ -158,7 +168,6 @@ interface LoaderOptions<S extends ContentStorage = ContentStorage, I18n extends
158
168
  typedPlugin: (plugin: LoaderPlugin<S>) => LoaderPlugin;
159
169
  }) => LoaderPluginOption[]);
160
170
  icon?: IconResolver;
161
- slugs?: SlugFn<S>;
162
171
  }
163
172
  interface ResolvedLoaderConfig {
164
173
  input: ResolvedInput;
@@ -465,4 +474,4 @@ declare function llms<C extends LoaderConfig = LoaderConfig>(loader: LoaderOutpu
465
474
  indexNode(node: Node, lang?: string): string;
466
475
  };
467
476
  //#endregion
468
- export { SlugFn as A, ContentStoragePageFile as B, LoaderPluginOption as C, createGetUrl as D, ResolvedLoaderConfig as E, PageTreeBuilderContext as F, PageTreeOptions as I, PageTreeTransformer as L, slugsFromData as M, slugsPlugin as N, loader as O, PageTreeBuilder as P, ContentStorage as R, LoaderPlugin as S, Page as T, FileSystem as V, InferMetaType as _, MetaData as a, LoaderOptions as b, SourceUnion as c, multiple as d, source as f, dynamicLoader as g, DynamicLoaderConfig as h, DynamicSource as i, getSlugs as j, types_d_exports as k, StaticSource as l, DynamicLoader as m, llms as n, PageData as o, update as p, path_d_exports as r, Source as s, LLMsConfig as t, VirtualFile as u, InferPageType as v, Meta as w, LoaderOutput as x, LoaderConfig as y, ContentStorageMetaFile as z };
477
+ export { SlugFn as A, ContentStorageMetaFile as B, LoaderPluginOption as C, createGetUrl as D, ResolvedLoaderConfig as E, PageTreeBuilder as F, FileSystem as H, PageTreeBuilderContext as I, PageTreeOptions as L, getSlugs as M, slugsFromData as N, loader as O, slugsPlugin as P, PageTreeTransformer as R, LoaderPlugin as S, Page as T, ContentStoragePageFile as V, InferMetaType as _, MetaData as a, LoaderOptions as b, SourceUnion as c, multiple as d, source as f, dynamicLoader as g, DynamicLoaderConfig as h, DynamicSource as i, SlugsPluginOptions as j, types_d_exports as k, StaticSource as l, DynamicLoader as m, llms as n, PageData as o, update as p, path_d_exports as r, Source as s, LLMsConfig as t, VirtualFile as u, InferPageType as v, Meta as w, LoaderOutput as x, LoaderConfig as y, ContentStorage as z };
@@ -776,7 +776,7 @@ function loader(...args) {
776
776
  }
777
777
  };
778
778
  }
779
- function resolveConfig(input, { slugs, icon, plugins = [], baseUrl, url, ...base }) {
779
+ function resolveConfig(input, { slugs, baseSlugs, icon, plugins = [], baseUrl, url, ...base }) {
780
780
  let config = {
781
781
  ...base,
782
782
  url: url ? (...args) => normalizeUrl(url(...args)) : createGetUrl(baseUrl, base.i18n),
@@ -784,7 +784,10 @@ function resolveConfig(input, { slugs, icon, plugins = [], baseUrl, url, ...base
784
784
  plugins: buildPlugins([
785
785
  icon && iconPlugin(icon),
786
786
  ...typeof plugins === "function" ? plugins({ typedPlugin: (plugin) => plugin }) : plugins,
787
- slugsPlugin(slugs)
787
+ slugsPlugin({
788
+ slugs,
789
+ baseSlugs
790
+ })
788
791
  ])
789
792
  };
790
793
  for (const plugin of config.plugins) {
@@ -1,8 +1,8 @@
1
1
  import { t as Awaitable } from "../types-D89QoQR-.js";
2
2
  import { n as I18nConfig } from "../index-DydiXvgS.js";
3
3
  import "../index-BM36H-xw.js";
4
- import { m as SharedIndex, n as SearchAPI, t as QueryOptions } from "../server-fnyWR-fq.js";
5
- import { x as LoaderOutput, y as LoaderConfig } from "../index-ByMgvmTr2.js";
4
+ import { m as SharedIndex, n as SearchAPI, t as QueryOptions } from "../server-BYa_JUH1.js";
5
+ import { x as LoaderOutput, y as LoaderConfig } from "../index-BNgjXvXj2.js";
6
6
  import { DocumentData, DocumentOptions } from "flexsearch";
7
7
  //#region src/search/server/build-doc.d.ts
8
8
  interface SharedDocument {
@@ -1,5 +1,5 @@
1
1
  import { r as SortedResult } from "../index-BM36H-xw.js";
2
- import { n as SearchAPI } from "../server-fnyWR-fq.js";
2
+ import { n as SearchAPI } from "../server-BYa_JUH1.js";
3
3
  import Mixedbread from "@mixedbread/sdk";
4
4
  import { StoreSearchResponse } from "@mixedbread/sdk/resources/stores";
5
5
  //#region src/search/mixedbread.d.ts
@@ -1,2 +1,2 @@
1
- import { a as AdvancedOptions, c as SimpleOptions, d as createSearchAPI, f as initAdvancedSearch, i as AdvancedIndex, l as createFromSource, n as SearchAPI, o as ExportedData, p as initSimpleSearch, r as SearchServer, s as Index, t as QueryOptions, u as createI18nSearchAPI } from "../server-fnyWR-fq.js";
1
+ import { a as AdvancedOptions, c as SimpleOptions, d as createSearchAPI, f as initAdvancedSearch, i as AdvancedIndex, l as createFromSource, n as SearchAPI, o as ExportedData, p as initSimpleSearch, r as SearchServer, s as Index, t as QueryOptions, u as createI18nSearchAPI } from "../server-BYa_JUH1.js";
2
2
  export { AdvancedIndex, AdvancedOptions, ExportedData, Index, QueryOptions, SearchAPI, SearchServer, SimpleOptions, createFromSource, createI18nSearchAPI, createSearchAPI, initAdvancedSearch, initSimpleSearch };
@@ -2,7 +2,7 @@ import { t as Awaitable } from "./types-D89QoQR-.js";
2
2
  import { i as StructuredData } from "./remark-structure-CnHwvNZr.js";
3
3
  import { n as I18nConfig } from "./index-DydiXvgS.js";
4
4
  import { r as SortedResult } from "./index-BM36H-xw.js";
5
- import { x as LoaderOutput, y as LoaderConfig } from "./index-ByMgvmTr2.js";
5
+ import { x as LoaderOutput, y as LoaderConfig } from "./index-BNgjXvXj2.js";
6
6
  import { Language, RawData, SearchParams, TypedDocument, ZBSearch, create } from "zbsearch";
7
7
  //#region src/search/zbsearch/create-db.d.ts
8
8
  type SimpleDocument = TypedDocument<ZBSearch<typeof simpleSchema>>;
@@ -1,2 +1,2 @@
1
- import { g as dynamicLoader, h as DynamicLoaderConfig, m as DynamicLoader } from "../index-ByMgvmTr2.js";
1
+ import { g as dynamicLoader, h as DynamicLoaderConfig, m as DynamicLoader } from "../index-BNgjXvXj2.js";
2
2
  export { DynamicLoader, DynamicLoaderConfig, dynamicLoader };
@@ -1,4 +1,4 @@
1
- import { i as isStaticSource, n as loader, r as isDynamicSource } from "../loader-cKlyDdAK.js";
1
+ import { i as isStaticSource, n as loader, r as isDynamicSource } from "../loader-9mGcCnIF.js";
2
2
  import { cache } from "react";
3
3
  //#region src/source/dynamic.ts
4
4
  function dynamicLoader(input, options) {
@@ -1,2 +1,2 @@
1
- import { B as ContentStoragePageFile, C as LoaderPluginOption, D as createGetUrl, E as ResolvedLoaderConfig, F as PageTreeBuilderContext, I as PageTreeOptions, L as PageTreeTransformer, O as loader, P as PageTreeBuilder, R as ContentStorage, S as LoaderPlugin, T as Page, V as FileSystem, _ as InferMetaType, a as MetaData, b as LoaderOptions, c as SourceUnion, d as multiple, f as source, i as DynamicSource, j as getSlugs, k as types_d_exports, l as StaticSource, n as llms, o as PageData, p as update, r as path_d_exports, s as Source, t as LLMsConfig, u as VirtualFile, v as InferPageType, w as Meta, x as LoaderOutput, y as LoaderConfig, z as ContentStorageMetaFile } from "../index-ByMgvmTr2.js";
1
+ import { B as ContentStorageMetaFile, C as LoaderPluginOption, D as createGetUrl, E as ResolvedLoaderConfig, F as PageTreeBuilder, H as FileSystem, I as PageTreeBuilderContext, L as PageTreeOptions, M as getSlugs, O as loader, R as PageTreeTransformer, S as LoaderPlugin, T as Page, V as ContentStoragePageFile, _ as InferMetaType, a as MetaData, b as LoaderOptions, c as SourceUnion, d as multiple, f as source, i as DynamicSource, k as types_d_exports, l as StaticSource, n as llms, o as PageData, p as update, r as path_d_exports, s as Source, t as LLMsConfig, u as VirtualFile, v as InferPageType, w as Meta, x as LoaderOutput, y as LoaderConfig, z as ContentStorage } from "../index-BNgjXvXj2.js";
2
2
  export { type ContentStorage, type ContentStorageMetaFile, type ContentStoragePageFile, type DynamicSource, FileSystem, InferMetaType, InferPageType, LLMsConfig, LoaderConfig, LoaderOptions, LoaderOutput, LoaderPlugin, LoaderPluginOption, Meta, type MetaData, Page, type PageData, type PageTreeBuilder, type PageTreeBuilderContext, type PageTreeOptions, type PageTreeTransformer, path_d_exports as PathUtils, ResolvedLoaderConfig, type Source, type SourceUnion, type StaticSource, type VirtualFile, type types_d_exports as _Internal, createGetUrl, getSlugs, llms, loader, multiple, source, update };
@@ -1,5 +1,5 @@
1
1
  import { o as path_exports } from "../path-1H5VzYiT.js";
2
- import { a as multiple, c as FileSystem, n as loader, o as source, s as update, t as createGetUrl } from "../loader-cKlyDdAK.js";
2
+ import { a as multiple, c as FileSystem, n as loader, o as source, s as update, t as createGetUrl } from "../loader-9mGcCnIF.js";
3
3
  import { getSlugs } from "./plugins/slugs.js";
4
4
  import { llms } from "./llms.js";
5
5
  export { FileSystem, path_exports as PathUtils, createGetUrl, getSlugs, llms, loader, multiple, source, update };
@@ -1,2 +1,2 @@
1
- import { n as llms, t as LLMsConfig } from "../index-ByMgvmTr2.js";
1
+ import { n as llms, t as LLMsConfig } from "../index-BNgjXvXj2.js";
2
2
  export { LLMsConfig, llms };
@@ -1,4 +1,4 @@
1
- import { S as LoaderPlugin } from "../../index-ByMgvmTr2.js";
1
+ import { S as LoaderPlugin } from "../../index-BNgjXvXj2.js";
2
2
  import { icons } from "lucide-react";
3
3
  //#region src/source/plugins/lucide-icons.d.ts
4
4
  /**
@@ -1,2 +1,2 @@
1
- import { A as SlugFn, M as slugsFromData, N as slugsPlugin, j as getSlugs } from "../../index-ByMgvmTr2.js";
2
- export { SlugFn, getSlugs, slugsFromData, slugsPlugin };
1
+ import { A as SlugFn, M as getSlugs, N as slugsFromData, P as slugsPlugin, j as SlugsPluginOptions } from "../../index-BNgjXvXj2.js";
2
+ export { SlugFn, SlugsPluginOptions, getSlugs, slugsFromData, slugsPlugin };
@@ -1,11 +1,15 @@
1
1
  import { n as dirname, r as extname, t as basename } from "../../path-1H5VzYiT.js";
2
2
  //#region src/source/plugins/slugs.ts
3
3
  /**
4
- * Generate slugs for pages if missing
4
+ * Generate slugs for pages if missing.
5
5
  */
6
- function slugsPlugin(slugFn) {
7
- function isIndex(file) {
8
- return basename(file, extname(file)) === "index";
6
+ function slugsPlugin(optsOrFn = {}) {
7
+ const prepended = /* @__PURE__ */ new WeakSet();
8
+ const { baseSlugs = [], slugs: slugFn } = typeof optsOrFn === "function" ? { slugs: optsOrFn } : optsOrFn;
9
+ function generateSlugs(path, file) {
10
+ const out = slugFn?.(file, () => getSlugs(path)) ?? getSlugs(path);
11
+ prepended.add(file);
12
+ return baseSlugs.length > 0 ? [...baseSlugs, ...out] : out;
9
13
  }
10
14
  return {
11
15
  name: "fumadocs:slugs",
@@ -14,13 +18,19 @@ function slugsPlugin(slugFn) {
14
18
  const taken = /* @__PURE__ */ new Set();
15
19
  for (const path of storage.getFiles()) {
16
20
  const file = storage.read(path);
17
- if (!file || file.format !== "page" || file.slugs) continue;
18
- const customSlugs = slugFn?.(file);
19
- if (customSlugs === void 0 && isIndex(path)) {
21
+ if (!file || file.format !== "page") continue;
22
+ if (file.slugs) {
23
+ if (baseSlugs.length > 0 && !prepended.has(file)) {
24
+ file.slugs = [...baseSlugs, ...file.slugs];
25
+ prepended.add(file);
26
+ }
27
+ continue;
28
+ }
29
+ if (basename(path, extname(path)) === "index") {
20
30
  indexFiles.push(path);
21
31
  continue;
22
32
  }
23
- file.slugs = customSlugs ?? getSlugs(path);
33
+ file.slugs = generateSlugs(path, file);
24
34
  const key = file.slugs.join("/");
25
35
  if (taken.has(key)) throw new Error(`Duplicated slugs: ${key}`);
26
36
  taken.add(key);
@@ -28,8 +38,11 @@ function slugsPlugin(slugFn) {
28
38
  for (const path of indexFiles) {
29
39
  const file = storage.read(path);
30
40
  if (file?.format !== "page") continue;
31
- file.slugs = getSlugs(path);
32
- if (taken.has(file.slugs.join("/"))) file.slugs.push("index");
41
+ file.slugs = generateSlugs(path, file);
42
+ if (taken.has(file.slugs.join("/"))) file.slugs = [...file.slugs, "index"];
43
+ const key = file.slugs.join("/");
44
+ if (taken.has(key)) throw new Error(`Duplicated slugs: ${key}`);
45
+ taken.add(key);
33
46
  }
34
47
  }
35
48
  };
@@ -1,5 +1,5 @@
1
1
  import { a as Separator$1, n as Item$1, t as Folder$1 } from "../../definitions-D8-KI7Uy.js";
2
- import { S as LoaderPlugin } from "../../index-ByMgvmTr2.js";
2
+ import { S as LoaderPlugin } from "../../index-BNgjXvXj2.js";
3
3
  import { ReactNode } from "react";
4
4
  //#region src/source/plugins/status-badges.d.ts
5
5
  interface Item extends Item$1 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "16.14.4",
3
+ "version": "16.14.5",
4
4
  "description": "The React.js library for building a documentation website",
5
5
  "keywords": [
6
6
  "Docs",